Example #1
0
    void OnCollisionEnter(Collision other)
    {
        Debug.Log(other.collider.tag);
        Debug.Log("Hit");
        state = ArmState.Hit;

        if (other.collider.tag == "Enemy")
        {
            TestEnemy en = other.collider.GetComponent <TestEnemy>();
            en.isFree = false;
            en.GetComponent <Collider>().enabled = false;
            enemyList.Add(en);
            enemyOffset.Add(trackPoint.position - en.transform.position);

            state = ArmState.Push;
            return;
        }

        //引かなくてよいかチェック
        foreach (Transform p in checkPoints)
        {
            float length = transform.localScale.x + 1;
            Ray   ray    = new Ray(p.position, p.right);
            Debug.DrawLine(p.position, p.position + (p.right * length), Color.red, 1f);

            if (Physics.Raycast(ray, length))
            {
                Debug.Log("Col > pull");

                //Armなら角度で引くスピードを上げる
                if (other.collider.tag == "Arm")
                {
                    Arm   otherArm = other.collider.GetComponent <Arm>();
                    float dir      = GetArmDir(otherArm);
                    if (dir < 90.0f && otherArm.state != ArmState.Pull)
                    {
                        Debug.Log("SpeedUp");
                        pullSpeed *= 6 * (1 - (dir / 90.0f)) + 1;
                    }
                }

                //押している敵を倒す
                foreach (TestEnemy en in enemyList)
                {
                    en.Death();
                }
                enemyList   = new List <TestEnemy>();
                enemyOffset = new List <Vector3>();

                return;
            }
        }

        state = ArmState.Push;
    }