Sunday 4 March 2018

fps shooter (PlayerScript)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityStandardAssets.CrossPlatformInput;

public class PlayerScript : MonoBehaviour
{
    public Animator Zombieanim;
    public float health = 100f;
    public Slider healthbar;
    public GameObject GameOverScreen;

    public float speed = 5.0f;
    private float rot = 0.0f;
    //public GameObject zombie;
    // Use this for initialization
    void Start () {
      
    }
  
    // Update is called once per frame
    void Update () {
       // CrossPlatformInputManager.GetAxis("Vertical");
    
    }
    void OnTriggerEnter(Collider col)
    {
        if (col.tag == "Enemy"&& !col.GetComponent<Enemy_AI>().isDead) {
            health = health - 0.1f;
            Zombieanim.SetBool ("attack",true);
        }
    }

    void OnTriggerStay(Collider col)
    {
        if (col.tag == "Enemy"&& !col.GetComponent<Enemy_AI>().isDead) {
            health = health - 0.1f;
            healthbar.value = health;

            if (health < 0f )
            {
                print ("you died");
                GameOverScreen.SetActive(true);
            }
        }
    }

    void OnTriggerExit(Collider col)
    {
        if (col.tag == "Enemy") {
            Zombieanim.SetBool ("attack",false);
        }
    }
 
}

No comments:

Post a Comment