当前位置: 首页>>代码示例>>C#>>正文


C# BoxCollider.GetComponent方法代码示例

本文整理汇总了C#中BoxCollider.GetComponent方法的典型用法代码示例。如果您正苦于以下问题:C# BoxCollider.GetComponent方法的具体用法?C# BoxCollider.GetComponent怎么用?C# BoxCollider.GetComponent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BoxCollider的用法示例。


在下文中一共展示了BoxCollider.GetComponent方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Setup

    protected virtual void Setup()
    {
        controller = new Controller(this);

        t = transform;
        rb = rigidbody;
        go = gameObject;
        sprite = GetComponentInChildren<tk2dSprite>();
        anim = GetComponentInChildren<tk2dSpriteAnimator>();

        bc = GetComponent<BoxCollider>();
        name = name + gameObject.GetInstanceID();
        botDetector = GameObject.Find(name + "/downDetector").GetComponent<BoxCollider>();
        leftDetector = GameObject.Find(name + "/leftDetector").GetComponent<BoxCollider>();
        rightDetector = GameObject.Find(name + "/rightDetector").GetComponent<BoxCollider>();
        topDetector = GameObject.Find(name + "/topDetector").GetComponent<BoxCollider>();

        botDScript = botDetector.GetComponent<FitzDetectBox>();
        leftDScript = leftDetector.GetComponent<FitzDetectBox>();
        rightDScript = rightDetector.GetComponent<FitzDetectBox>();
        topDScript = topDetector.GetComponent<FitzDetectBox>();

        Debug.Log ("My right detector is " + rightDetector.gameObject.GetInstanceID());

        dummy = GameObject.Find(name + "/dummy");
        bc.size = new Vector3(sprite.CurrentSprite.colliderVertices[1].x * 2, sprite.CurrentSprite.colliderVertices[1].y * 2, 10);
        Debug.Log ("Fitting detectors for " + gameObject.GetInstanceID());
        FitDetectors();
    }
开发者ID:TimuSumisu,项目名称:recess-race,代码行数:29,代码来源:Platformer.cs

示例2: DetectorEnter

    public override void DetectorEnter(BoxCollider detector, BoxCollider colEntering)
    {
        base.DetectorEnter (detector, colEntering);
        Doc docScript = colEntering.GetComponent<Doc>();

        if (docScript){				//what happens when what I hit is Doc?

            if(currentMotor == mondo){		//Am I mario or what

                if (velocity.y > 0 && docScript.Dangerous){
                    Debug.Log("Get hurt!");
                }

                else if (detector == botDetector && docScript.JumpedOn(controller.getRun) && velocity.y < 0){		//where did I hit? Do I jump? If I jump, do I rebound (JumpedOn gives me this result; see Doc.cs)
                    velocity = new Vector2(velocity.x, controller.getJump? mondo.jExtraHeight : mondo.jHeight);
                }
                else if ((detector == rightDetector || detector == leftDetector)){
                    if (docScript.Dangerous){			//should the shell hurt me?
                        Debug.Log("Get hurt!");
                        Dying = true;
                    }
                    else if (!controller.getRun){ 		//should I kick the shell?
                        docScript.Kicked();
                        pMeter = 0;
                        velocity = new Vector2(0, velocity.y);
                    }
                    else {				//or I guess I should hold on to it
                        ballHolding = docScript.transform;
                        docScript.Held = true;
                        Debug.Log("Hold that ball");
                    }
                }
                else if (!docScript.Dangerous && controller.getRun){
                    ballHolding = docScript.transform;
                    docScript.Held = true;
                    Debug.Log("Holding ball now");
                }
            }
            else if (currentMotor == pinky){

                //TODO : hurt Doc; he always gets hurt if I touch him, unless I'm spitting him out.
                if ((detector == topDetector || detector == botDetector) && !meteor){
                    //TODO: Hurt self because I'm not going fast enough to be a weapon
                    Dying = true;
                    return;
                }

                if (((detector == rightDetector && FacingRight) || (detector == leftDetector && !FacingRight)) && agape){
                    docScript.Inhaled();
                    mouthFull = true;
                    inMouth = docScript.gameObject;
                    agape = false;
                    anim.Play(PinkyIdle);

                }
            }
        } 		//end if docscript
        else if (detector == botDetector){

            Checkpoint checkScript = colEntering.GetComponent<Checkpoint>();
            if (checkScript != null){
                checkScript.Enter ();
                Debug.Log ("There's a checkpoint script.");
            }
        }
        else if (detector == topDetector && currentMotor == mondo){
            BrickBlock brickScript = colEntering.GetComponent<BrickBlock>();

            if (brickScript){
                brickScript.SendMessage("Explode");
            }
        }

        if (colEntering.gameObject.layer == LayerMask.NameToLayer("normalCollision") && (detector == leftDetector || detector == rightDetector) && charging){
            EndCharge ();
        }
        int layer = colEntering.gameObject.layer;
        if (layer == 31 && colEntering.tag == "spike"){
            Debug.Log ("OUCH");
            Dying = true;
        }
    }
开发者ID:TimuSumisu,项目名称:recess-race,代码行数:82,代码来源:Fitz.cs


注:本文中的BoxCollider.GetComponent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。