all repos — RPG @ ad2c182a4f6dcf471dea0a0d304cc0bd6028c353

Fully functional 3D turn based role playing game coded in C# and base Unity.

Assets/Scripts/Overworld/FollowAI.cs (view raw)

 1using System.Collections;
 2using System.Collections.Generic;
 3using UnityEngine;
 4
 5[RequireComponent(typeof(CapsuleCollider))]
 6public class FollowAI : MonoBehaviour
 7{
 8    private Transform orc;
 9    private Animator anim;
10    public bool gotem = false;
11    private float moveSpeed = 1;
12    
13    void Start()
14    {
15        orc = transform.GetChild(0);
16        anim = orc.GetComponent<Animator>();
17    }
18
19    private void OnTriggerEnter(Collider other)
20    {
21        if (other.gameObject.name == "Player")
22        {
23            gotem = true;
24            //anim.SetTrigger("Spotted");
25        }
26    }
27
28    private void OnTriggerStay(Collider other)
29    {
30        if (other.gameObject.name == "Player")
31        {
32            gotem = true;
33            anim.SetBool("Moving", true);
34            orc.LookAt(other.transform);
35            transform.Translate(orc.forward * Time.deltaTime * moveSpeed);
36        }
37    }
38
39    private void OnTriggerExit(Collider other)
40    {
41        if (other.gameObject.name == "Player")
42        {
43            gotem = false;
44            anim.SetBool("Moving", false);
45            //anim.SetTrigger("Lost");
46        }
47    }
48}