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


C# BoxCollider2D.GetComponent方法代码示例

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


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

示例1: Awake

    public override void Awake()
    {
        MoveAnimation = MoveAnim.Idle;

        xScale = this.transform.localScale.x;

        interactTrigger = transform.Find("Interact").GetComponent<BoxCollider2D>();
        bodyCol = GetComponent<CircleCollider2D>();
        _MoveInteractTrigger = interactTrigger.GetComponent<MoveInteractTrigger>();

        Canvas playerCanvas = GetComponentInChildren<Canvas>();
        if (playerCanvas != null)
        {
            playerCanvasTransform = playerCanvas.transform;
        }

        base.Awake();
    }
开发者ID:Mrbransky,项目名称:Kissy_Ghost,代码行数:18,代码来源:Player.cs

示例2: CheckCollision

    public void CheckCollision(BoxCollider2D box1, BoxCollider2D box2)
    {
        float Box1Left = box1.transform.position.x + (box1.offset.x - box1.size.x * 0.5f) * box1.transform.localScale.x;
        float Box1Right = box1.transform.position.x + (box1.offset.x + box1.size.x * 0.5f) * box1.transform.localScale.x;// * box2.transform.localScale.x);
        float Box1Top = box1.gameObject.transform.position.y + (box1.offset.y + box1.size.y * 0.5f) * box1.transform.localScale.y;
        float Box1Bottom = box1.transform.position.y + (box1.offset.y - box1.size.y * 0.5f) * box1.transform.localScale.y;// * box2.transform.localScale.y);

        float Box2Left = box2.transform.position.x + (box2.offset.x - box2.size.x * 0.5f) * box2.transform.localScale.x;
        float Box2Right = box2.transform.position.x + (box2.offset.x + box2.size.x * 0.5f) * box2.transform.localScale.x;// * box2.transform.localScale.x);
        float Box2Top = box2.gameObject.transform.position.y + (box2.offset.y + box2.size.y * 0.5f) * box2.transform.localScale.y;
        float Box2Bottom = box2.transform.position.y + (box2.offset.y - box2.size.y * 0.5f) * box2.transform.localScale.y;// * box2.transform.localScale.y);

        //Debug.Log("STP->box2:" + box2.name + ":Box2Left=" + Box2Left + ":Box2Right=" + Box2Right + "\t:Box2Top=" + Box2Top + "\t:Box2Bottom=" + Box2Bottom + "\tbox2.transform.position.y=" + box2.gameObject.transform.position.y + "\t:box2.offset.y=" + box2.offset.y);
        bool collisionOnBox2Left = ((Box1Left <= Box2Left) && (Box1Right >= Box2Left)); //collision on box2Left if 
        bool collisionOnBox2Right = ((Box1Left <= Box2Right) && (Box1Right >= Box2Right)); //collision on Box2Right
        bool collisionOnBox2Top = ((Box1Top >= Box2Top) && (Box1Bottom <= Box2Top)); //collision on Box2Top
        bool collisionOnBox2Bottom = ((Box1Top >= Box2Bottom) && (Box1Bottom <= Box2Bottom)); //collision on Box2Right

        bool box1ContainsBox2Horizontally = ((Box1Left >= Box2Left) && (Box1Right <= Box2Right));
        bool box1ContainsBox2Vertically = ((Box1Top <= Box2Top) && (Box1Bottom >= Box2Bottom));

        //Debug.Log("STP->collisionOnBox2Left=" + collisionOnBox2Left + "\t collisionOnBox2Right=" + collisionOnBox2Right + "\t collisionOnBox2Top=" + collisionOnBox2Top + "\t collisionOnBox2Bottom=" + collisionOnBox2Bottom 
        //    + "\t box1ContainsBox2Horizontally=" + box1ContainsBox2Horizontally + "\t box1ContainsBox2Vertically=" + box1ContainsBox2Vertically);
        bool thereIsACollision = false;

        if ((collisionOnBox2Right && collisionOnBox2Top) || (collisionOnBox2Right && collisionOnBox2Bottom) || (collisionOnBox2Right && box1ContainsBox2Vertically))
        {
            //Debug.Log("STP->collision true on box 2 right");
            thereIsACollision = true;
        }

        if ((collisionOnBox2Left && collisionOnBox2Top) || (collisionOnBox2Left && collisionOnBox2Bottom) || (collisionOnBox2Left && box1ContainsBox2Vertically))
        {
            //Debug.Log("STP->collision true on box 2 leftt");
            thereIsACollision = true;
        }


        if ((box1ContainsBox2Horizontally && collisionOnBox2Top) || (box1ContainsBox2Horizontally && collisionOnBox2Bottom) || (box1ContainsBox2Horizontally && box1ContainsBox2Vertically))
        {
            //Debug.Log("STP->collision true on box 2 contains box 1 horizontally");
            thereIsACollision = true;
        }

        if (thereIsACollision)
        {
            CharacterControllerScript character = box1.GetComponent<CharacterControllerScript>();
            if (character != null)
            {
                if (box2.tag == "Ground") { character.GroundCollision(); }
                if (box2.tag == "Finish") { character.FinishCollision(); }
                if (box2.tag == "BEar")
                {

                    DOCTORBEAR docBear = box2.GetComponent<DOCTORBEAR>();
                    if (docBear != null)
                        docBear.OnShowSpeechBubble();
                }
                if (box2.tag == "death") { GameManager.GetInstance().Respawn(); }
                if (box2.tag == "MeteorSpawner")
                {
                    MeteorSpawner spawner = box2.GetComponent<MeteorSpawner>();
                    if (spawner != null)
                        spawner.Spawn();
                }

            }
        }
    }
开发者ID:denis-bezeau,项目名称:GGJ2016,代码行数:69,代码来源:CollisionDetectorHack.cs

示例3: Start

 // Use this for initialization
 void Start() {
     isOn = false;
     playerCollider = GameObject.FindGameObjectWithTag("Player").GetComponent<BoxCollider2D>();
     player = playerCollider.GetComponent<Player>();
     thisCollider = GetComponent<BoxCollider2D>();
 }
开发者ID:griffin-harris,项目名称:GameProject,代码行数:7,代码来源:Checkpoint.cs

示例4: PerformColliderCalculations

    private void PerformColliderCalculations(BoxCollider2D collider, ref Vector2 position1, ref Vector2 position2)
    {
        var script = collider.GetComponent<PositionHelper>();
        if (script == null)
        {
            Debug.LogError("Detected Enemy does not have a Position Helper component");
            return;
        }

        var relativePosition
            = new Vector2(transform.position.x - collider.transform.position.x, transform.position.y - collider.transform.position.y);

        Resources.RotatePositionVectorAboutOrigin(ref relativePosition, script.AngleOfRotation);

        var cornerPositions = script.Positions;
        var cornerRelativePositions = script.RelativePositionsToCenter;

        if (Resources.IsBetween(relativePosition.x, cornerRelativePositions._topLeft.x, cornerRelativePositions._bottomRight.x))
        {
            if (relativePosition.y > cornerRelativePositions._topLeft.y)
            {
                position1 = cornerPositions._topLeft;
                position2 = cornerPositions._topRight;
                _backgroundManager.AddPositions(position1, position2);
                return;
            }

            if (relativePosition.y < cornerRelativePositions._bottomRight.y)
            {
                position1 = cornerPositions._bottomLeft;
                position2 = cornerPositions._bottomRight;
                _backgroundManager.AddPositions(position1, position2);
                return;
            }
        }

        if (Resources.IsBetween(relativePosition.y, cornerRelativePositions._bottomRight.y, cornerRelativePositions._topRight.y))
        {
            if (relativePosition.x > cornerRelativePositions._topRight.x)
            {
                position1 = cornerPositions._bottomRight;
                position2 = cornerPositions._topRight;
                _backgroundManager.AddPositions(position1, position2);
                return;
            }

            if (relativePosition.x < cornerRelativePositions._bottomRight.x)
            {
                position1 = cornerPositions._bottomLeft;
                position2 = cornerPositions._topLeft;
                _backgroundManager.AddPositions(position1, position2);
                return;
            }
        }

        if (relativePosition.x > cornerRelativePositions._topRight.x && relativePosition.y > cornerRelativePositions._topRight.y)
        {
            position1 = cornerPositions._topLeft;
            position2 = cornerPositions._bottomRight;
            _backgroundManager.AddPositions(position1, position2);
            return;
        }

        if (relativePosition.x > cornerRelativePositions._bottomRight.x && relativePosition.y < cornerRelativePositions._bottomRight.y)
        {
            position2 = cornerPositions._topRight;
            position1 = cornerPositions._bottomLeft;
            _backgroundManager.AddPositions(position1, position2);
            return;
        }

        if (relativePosition.x < cornerRelativePositions._bottomLeft.x && relativePosition.y < cornerRelativePositions._bottomLeft.y)
        {
            position1 = cornerPositions._topLeft;
            position2 = cornerPositions._bottomRight;
            _backgroundManager.AddPositions(position1, position2);
            return;
        }

        if (relativePosition.x < cornerRelativePositions._topLeft.x && relativePosition.y > cornerRelativePositions._topLeft.y)
        {
            position1 = cornerPositions._topRight;
            position2 = cornerPositions._bottomLeft;
            _backgroundManager.AddPositions(position1, position2);
            return;
        }
    }
开发者ID:sathiyavrs,项目名称:Hit-The-Green-Cube,代码行数:87,代码来源:FriendlyReconManager.cs

示例5: StartTask

    public void StartTask(string taskName, BoxCollider2D focusArea)
    {
        Vector2 aa = Camera.main.WorldToScreenPoint(focusArea.GetComponent<BoxCollider2D>().bounds.min);
        Vector2 bb = Camera.main.WorldToScreenPoint(focusArea.GetComponent<BoxCollider2D>().bounds.max);

        Debug.Log("AA" + aa.x);
        Debug.Log("BB" + bb.x);

        allExperients[curExperiment].StartTask(taskName, new Vector2((int)aa.x, (int)aa.y), new Vector2((int)bb.x, (int)bb.y));
    }
开发者ID:Amaranthos,项目名称:UnityEyeTrackingAPI,代码行数:10,代码来源:Session.cs


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