예제 #1
0
 private void OnCollisionEnter(Collision collision)
 {
     if (ProjectileBehaviour == Type.FirstPerson)
     {
         TestEnemy enemyHit = collision.collider.GetComponent <TestEnemy>();
         if (enemyHit)
         {
             if (enemyHit.DiesFromBounces && enemyHit.BouncesNeededToDie == Bounces)
             {
                 enemyHit.Die();
             }
             else
             if (enemyHit.DiesFromBounces && enemyHit.BouncesNeededToDie > Bounces)
             {
                 Die();
             }
             else
             if (enemyHit.DiesFromDamage)
             {
                 enemyHit.TakeDamage(Damage);
             }
         }
         Vector3 bounceDirection = Vector3.Reflect(transform.forward, collision.contacts[0].normal);
         Bounces++;
         Instantiate(HitSmoke, transform.position + Vector3.forward * .5f, Random.rotation);
         transform.forward = bounceDirection;
     }
 }
예제 #2
0
    private void Update()
    {
        //time check
        if (DeathByTime)
        {
            timer += Time.deltaTime;
            if (timer >= LifeTime)
            {
                Die();
            }
        }

        //movement
        transform.Translate(Vector3.forward * MoveSpeed * Time.deltaTime);

        //raycast for topdown
        if (ProjectileBehaviour == Type.TopDown)
        {
            Ray        ray = new Ray(transform.position, transform.forward);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit, Time.deltaTime * MoveSpeed + .2f, collisionMask))
            {
                TestEnemy enemyHit = hit.collider.GetComponent <TestEnemy>();
                if (enemyHit)
                {
                    if (enemyHit.DiesFromBounces && enemyHit.BouncesNeededToDie == Bounces)
                    {
                        enemyHit.Die();
                    }
                    else
                    if (enemyHit.DiesFromBounces && enemyHit.BouncesNeededToDie > Bounces)
                    {
                        Die();
                    }
                    else
                    if (enemyHit.DiesFromDamage && enemyHit.Health == Damage)
                    {
                        enemyHit.TakeDamage(Damage);
                        return;
                    }
                }
                Vector3 bounceDirection = Vector3.Reflect(ray.direction, hit.normal);
                float   rot             = 90 - Mathf.Atan2(bounceDirection.z, bounceDirection.x) * Mathf.Rad2Deg;
                transform.eulerAngles = new Vector3(0, rot, 0);
                if (DeathByBounces)
                {
                    Bounces++;
                    Instantiate(HitSmoke, transform.position + Vector3.forward * .5f, Random.rotation);
                }
            }
        }
    }