Skip to content

Instantly share code, notes, and snippets.

@Templar2020
Created July 19, 2017 10:10
Show Gist options
  • Save Templar2020/49ca40f6bc0667e59d3049d2d3ae5f0d to your computer and use it in GitHub Desktop.
Save Templar2020/49ca40f6bc0667e59d3049d2d3ae5f0d to your computer and use it in GitHub Desktop.
Chicken Game
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!");
}
}
}
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