Created
December 23, 2019 09:08
-
-
Save IshidaGames/598dc7f298f13bd066b22680e5d6ba6f to your computer and use it in GitHub Desktop.
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 System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using UnityEngine.AI; | |
[RequireComponent(typeof(CapsuleCollider))] | |
[RequireComponent(typeof(Rigidbody))] | |
[RequireComponent(typeof(NavMeshAgent))] | |
public class Monster : MonoBehaviour | |
{ | |
private GameObject player; | |
NavMeshAgent agent; | |
Animator animator; | |
Rigidbody rb; | |
CapsuleCollider caps; | |
bool defeat = true; | |
void Start() | |
{ | |
agent = GetComponent<NavMeshAgent>(); | |
animator = GetComponent<Animator>(); | |
caps = GetComponent<CapsuleCollider>(); | |
rb = GetComponent<Rigidbody>(); | |
player = GameObject.Find("SantaRider"); | |
} | |
void Update() | |
{ | |
agent.destination = player.transform.position; | |
rb.constraints = RigidbodyConstraints.FreezePosition; | |
} | |
private void OnTriggerEnter(Collider other) | |
{ | |
if (other.gameObject.tag == "Explosion" && defeat) | |
{ | |
agent.isStopped = true; | |
animator.SetBool("IsDead", true); | |
caps.enabled = false; | |
GameObject defeatObj = GameObject.Find("DefeatCount"); | |
DefeatCount defeatScr = defeatObj.GetComponent<DefeatCount>(); | |
defeatScr.AddCount(); | |
defeat = false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment