Skip to content

Instantly share code, notes, and snippets.

@IshidaGames
Created December 23, 2019 09:08
Show Gist options
  • Save IshidaGames/598dc7f298f13bd066b22680e5d6ba6f to your computer and use it in GitHub Desktop.
Save IshidaGames/598dc7f298f13bd066b22680e5d6ba6f to your computer and use it in GitHub Desktop.
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