// Start is called before the first frame update
    void Start()
    {
        cam      = Camera.main;
        camOrbit = cam.GetComponentInParent <Powers_CamOrbit>();
        pawn     = GetComponent <CharacterController>();

        targetingSystem = GetComponent <Powers_PlayerTargeting>();
        healthSystem    = GetComponent <Powers_HealthSystem>();
        playerSource    = GetComponent <AudioSource>();

        torsoPoint = torso.GetComponent <Powers_PointAt>();
        armPointL  = armL.GetComponent <Powers_PointAt>();
        armPointR  = armR.GetComponent <Powers_PointAt>();

        legLxRotLastFrame = legL.localRotation.x;
        legLzRotLastFrame = legL.localRotation.z;
    }
    private void OnTriggerEnter(Collider other)
    {
        if (!particlesSpawned) //Check to make sure projectile isnt getting destroyed
        {
            //grab player movement or turret AI script
            Powers_PlayerMovement player = other.GetComponent <Powers_PlayerMovement>();

            if (player) //check if player movement script is null. if not, then we have a player
            {
                Powers_HealthSystem playerHealth = player.GetComponent <Powers_HealthSystem>();
                if (playerHealth)
                {
                    playerHealth.TakeDamage(damage);
                }
                projectileSource.PlayOneShot(hitSFX);
            }

            ProjectileDestroy();
        }
    }
    private void DoAttack()
    {
        if (shootCooldown > 0)
        {
            return;                    //too soon
        }
        if (!wantsToTarget)
        {
            return;                 //player not targeting
        }
        if (!wantsToAttack)
        {
            return;                 //player not shooting
        }
        if (target == null)
        {
            return;                 //no target available
        }
        if (!CanSeeThing(target))
        {
            return;                       //target not in sight
        }
        //set cooldown
        shootCooldown = 1 / roundPerSecond;

        Powers_HealthSystem targetHealth = target.GetComponent <Powers_HealthSystem>();

        if (targetHealth)
        {
            targetHealth.TakeDamage(Random.Range(18, 25));
            //if target has been killed, add one to the kill count.
        }

        //attack!

        if (pistolL && pistolLNext)
        {
            Instantiate(prefabMuzzleFlash, pistolL.position, pistolL.rotation);
            pistolLSource.PlayOneShot(pistolShot);
        }
        if (pistolR && !pistolLNext)
        {
            Instantiate(prefabMuzzleFlash, pistolR.position, pistolR.rotation);
            pistolRSource.PlayOneShot(pistolShot);
        }

        camOrbit.Shake(2);

        //trigger arm anim

        //rotates arms up:
        if (pistolLNext)
        {
            armL.localEulerAngles += new Vector3(-15, 0, 0);
        }
        else
        {
            armR.localEulerAngles += new Vector3(-15, 0, 0);
        }

        //move arms back:
        if (pistolLNext)
        {
            armL.position += -armL.transform.forward * .05f;
        }
        else
        {
            armR.position += -armR.transform.forward * .05f;
        }

        pistolLNext = !pistolLNext;
    }
Exemple #4
0
 // Start is called before the first frame update
 void Start()
 {
     turretHealth = GetComponent <Powers_HealthSystem>();
     playerHealth = turretAI.playerMovementScript.GetComponent <Powers_HealthSystem>();
 }