コード例 #1
0
 void Awake()
 {
     // Setup references
     player       = GameObject.FindGameObjectWithTag("Player").transform;
     playerHealth = player.GetComponent <SandCharHealth>();
     enemyHealth  = GetComponent <SandEnemyHealth>();
     nav          = GetComponent <NavMeshAgent>();
 }
コード例 #2
0
    void Shoot()
    {
        // Reset timer
        timer = 0f;

        // Play gun audio
        //gunAudio.Play();

        // Flash gun's light
        //gunLight.enabled = true;

        // Start/reset gun particle effects
        //gunParticles.Stop();
        //gunParticles.Play();

        // Set first point of visible shot line at gun barrel
        shotLine.enabled = true;
        shotLine.SetPosition(0, transform.position);

        // Set first point & direction of shotFired ray
        shotFired.origin    = transform.position;
        shotFired.direction = transform.forward;

        // Raycast against shootable objects; if it hits anything...
        if (Physics.Raycast(shotFired, out shotHit, shotRange, shootableMask))
        {
            // See if hit object has EnemyHealth script
            SandEnemyHealth enemyHealth = shotHit.collider.GetComponent <SandEnemyHealth>();

            // If hit object does have EnemyHelth, it takes damage
            if (enemyHealth != null)
            {
                enemyHealth.TakeDamage(damageAmount, shotHit.point);
            }

            // Set end of line renderer at hit object
            shotLine.SetPosition(1, shotHit.point);
        }
        // Otherwise, if didn't hit anything shootable
        else
        {
            // Extend gunshot line out to range limit
            shotLine.SetPosition(1, shotFired.origin + shotFired.direction * shotRange);
        }
    }
コード例 #3
0
    private void OnTriggerEnter(Collider other)
    {
        // If colliding with an enemy hitbox...
        if (other.CompareTag("Enemy"))
        {
            // ... set hitable to true
            hitable = true;

            // Also make note of enemy being hit (so we know who's health to decrease)
            enemyHealth = other.GetComponentInParent <SandEnemyHealth>();
        }

        // If player collides with head collider on enemy...
        if (other.GetType() == typeof(SphereCollider))
        {
            // ... destroy this enemy
            Destroy(other.gameObject);
        }
    }
コード例 #4
0
    void Awake()
    {
        // Setup references
        enemyHealth = GetComponent <SandEnemyHealth>();
        nav         = GetComponent <NavMeshAgent>();

        // Setup patrol bounds based on x or z axis
        if (patrolXSize == 0)
        {
            patrolZBoundMin = transform.position.z - patrolZSize;
            patrolZBoundMax = transform.position.z + patrolZSize;

            // Start by moving left towards patrolBoundMin
            nav.SetDestination(new Vector3(transform.position.x, transform.position.y, patrolZBoundMin));
        }
        else if (patrolZSize == 0)
        {
            patrolXBoundMin = transform.position.x - patrolXSize;
            patrolXBoundMax = transform.position.x + patrolXSize;

            // Start by moving left towards patrolBoundMin
            nav.SetDestination(new Vector3(patrolXBoundMin, transform.position.y, transform.position.z));
        }
    }