Example #1
0
 void GetDamageable(GameObject target)
 {
     if (target)
     {
         ADamageable damageable = target.GetComponent <ADamageable>();
         if (damageable && !mDamageables.ContainsKey(target.GetInstanceID()))
         {
             mDamageables.Add(target.GetInstanceID(), damageable);
         }
     }
 }
Example #2
0
 private void OnTriggerEnter2D(Collider2D otherCol)
 {
     if (otherCol.CompareTag("Player"))
     {
         ADamageable damageable = otherCol.GetComponent <ADamageable>();
         if (damageable)
         {
             damageable.OnHitObstacle();
         }
     }
 }
Example #3
0
    public void Shoot(int playerId)
    {
        if (playerId != GameJamGameManager.LocalPlayerId)
        {
            return;
        }

        if (timer < timeBetweenBullets)
        {
            return;
        }
        // Reset the timer.
        timer = 0f;

        // Play the gun shot audioclip.
        if (!gunAudio.isPlaying)
        {
            gunAudio.Play();
        }

        // Enable the lights.
        gunLight.enabled  = true;
        faceLight.enabled = true;

        // Stop the particles from playing if they were, then start the particles.
        gunParticles.Stop();
        gunParticles.Play();

        // Enable the line renderer and set it's first position to be the end of the gun.
        gunLine.enabled = true;
        gunLine.SetPosition(0, transform.position);

        // Set the shootRay so that it starts at the end of the gun and points forward from the barrel.
        shootRay.origin    = transform.position;
        shootRay.direction = transform.forward;
        // Perform the raycast against gameobjects on the shootable layer and if it hits something...
        //if(Physics.Raycast (shootRay, out shootHit, range, shootableLayers))
        if (Physics.SphereCast(shootRay.origin, autoAimRadius, shootRay.direction, out shootHit, range, shootableLayers))
        {
            if (GameJamGameManager.LocalPlayerId == playerId)
            {
                // Try and find an EnemyHealth script on the gameobject hit.
                ADamageable enemy = shootHit.collider.GetComponent <ADamageable> ();

                // If the EnemyHealth component exist...
                if (enemy != null)
                {
                    // ... the enemy should take damage.
                    enemy.TakeDamage(playerColorId, damagePerShot, shootHit.point);
                }
                else
                {
                    Debug.Log("Enemy is null tho");
                }
            }
            else
            {
                Debug.Log("Not doing damage!");
            }

            // Set the second position of the line renderer to the point the raycast hit.
            gunLine.SetPosition(1, shootHit.point);
        }
        // If the raycast didn't hit anything on the shootable layer...
        else
        {
            // ... set the second position of the line renderer to the fullest extent of the gun's range.
            gunLine.SetPosition(1, shootRay.origin + shootRay.direction * range);
        }
    }