Created
July 19, 2017 10:10
-
-
Save Templar2020/49ca40f6bc0667e59d3049d2d3ae5f0d to your computer and use it in GitHub Desktop.
Chicken Game
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEngine.UI; | |
public class playerHealth : MonoBehaviour | |
{ | |
public const int maxHealth = 100; | |
public int currentHealth = maxHealth; | |
public Text hp; | |
public Text maxHP; | |
void Update(){ | |
hp.text = currentHealth.ToString(); | |
maxHP.text = maxHealth.ToString(); | |
} | |
public void TakeDamage(int amount) | |
{ | |
currentHealth -= amount; | |
if (currentHealth <= 0) | |
{ | |
currentHealth = 0; | |
Debug.Log("Dead!"); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class wolfAI : MonoBehaviour { | |
public float moveSpeed; | |
public Transform target; | |
void Update(){ | |
} | |
void OnTriggerStay(Collider other) | |
{ | |
if(other.gameObject.name == "Player"){ | |
transform.LookAt(target); | |
transform.Translate(Vector3.forward*moveSpeed*Time.deltaTime); | |
} | |
} | |
void OnCollisionEnter(Collision collision) | |
{ | |
var hit = collision.gameObject; | |
var health = hit.GetComponent<playerHealth>(); | |
if (health != null) | |
{ | |
health.TakeDamage(10); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment