コード例 #1
0
ファイル: BounceBullet.cs プロジェクト: supernikx/TanksOnline
    private void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.layer == LayerMask.NameToLayer("Tank"))
        {
            TankController hitTank = collision.gameObject.GetComponent <TankController>();
            if (hitTank)
            {
                if (hitTank.GetPlayer() != tankCtrl.GetPlayer())
                {
                    tankCtrl.ChangeWeapon();
                    hitTank.Kill();
                }
            }

            Destroy(gameObject);
            return;
        }

        currentBounce++;
        if (currentBounce == maxBounce)
        {
            Destroy(gameObject);
        }
        else
        {
            Vector3 newDirection = Vector3.Reflect(transform.forward, collision.contacts[0].normal);
            transform.rotation = Quaternion.LookRotation(newDirection, Vector3.up);
        }
    }
コード例 #2
0
    private void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.layer == LayerMask.NameToLayer("Tank"))
        {
            TankController hitTank = collision.gameObject.GetComponent <TankController>();
            if (hitTank)
            {
                if (hitTank.GetPlayer() != tankCtrl.GetPlayer())
                {
                    tankCtrl.ChangeWeapon();
                    hitTank.Kill();
                    Destroy(gameObject);
                }
            }
            return;
        }

        Destroy(gameObject);
    }