コード例 #1
0
 // Update is called once per frame
 void Update()
 {
     transform.Translate(-moveSpeed * Time.deltaTime, 0, 0);
     if ((Time.time - startTime) > life)
     {
         balloonManager.RemoveBalloon(gameObject);
         balloonManager.life -= 1;
         Destroy(gameObject);
     }
 }
    void BoundingBoxCheck()
    {
        isCollided = false;
        for (int i = 0; i < colliderBalloon.Count; i++)
        {
            List <Vector3> colliderPoints = new List <Vector3>();
            colliderPoints.Add(new Vector3(colliderBalloon[i].transform.position.x + 0.42f, colliderBalloon[i].transform.position.y + 0.42f));
            colliderPoints.Add(new Vector3(colliderBalloon[i].transform.position.x - 0.42f, colliderBalloon[i].transform.position.y + 0.42f));
            colliderPoints.Add(new Vector3(colliderBalloon[i].transform.position.x - 0.42f, colliderBalloon[i].transform.position.y - 0.42f));
            colliderPoints.Add(new Vector3(colliderBalloon[i].transform.position.x + 0.42f, colliderBalloon[i].transform.position.y - 0.42f));
            for (int j = 0; j < colliderPoints.Count; j++)  //障碍物顶点两两组成一条边,分别进行判断
            {
                if (j == colliderPoints.Count - 1)
                {
                    _helpPointA = _armatureComp.transform.InverseTransformPoint(colliderPoints[j]);  //将障碍物坐标变换到骨架局部坐标
                    _helpPointB = _armatureComp.transform.InverseTransformPoint(colliderPoints[0]);
                }
                else
                {
                    _helpPointA = _armatureComp.transform.InverseTransformPoint(colliderPoints[j]);
                    _helpPointB = _armatureComp.transform.InverseTransformPoint(colliderPoints[j + 1]);
                }
                //判断线段是否与骨架的所有插槽的自定义包围盒相交
                Slot intersectsSlots = this._armatureComp.armature.IntersectsSegment(this._helpPointA.x, this._helpPointA.y,
                                                                                     this._helpPointB.x, this._helpPointB.y,
                                                                                     this._intersectionPointA, _intersectionPointB, _normalRadians);
                //判断点是否在所有插槽的自定义包围盒内
                //Slot containsTargetA = this._armatureComp.armature.ContainsPoint(this._helpPointA.x, this._helpPointA.y);
                //Slot containsTargetB = this._armatureComp.armature.ContainsPoint(this._helpPointB.x, this._helpPointB.y);

                if (intersectsSlots != null)
                {
                    isCollided = true;
                    colliderBalloon[i].GetComponent <BalloonAttack>().Hit();
                    balloonManager.RemoveBalloon(i);
                    balloonManager.score += 10;
                    break;
                }
            }
        }
    }