Files
racesm/Assets/Scripts/NPC improved.cs
magn9775 d9b73bd148 NPC
2024-04-22 10:06:47 +02:00

50 lines
1.1 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NPCimproved : MonoBehaviour
{
public Animator animator;
public GameObject npcPrefab;
public AudioSource audio;
private bool walking = true;
void Start()
{
}
void Update()
{
if (walking)
{
//npcPrefab.transform.position += new Vector3(0,0,0.005f);
npcPrefab.transform.position += transform.forward * Time.deltaTime;
}
//animator.SetBool("IsTurning", false);
}
// Disabels the animation controller, to simulate getting hit by car
void OnCollisionEnter(Collision col) {
if (col.gameObject.tag == "Player")
{
if (walking)
{
audio.Play();
animator.runtimeAnimatorController = Resources.Load("m_Controller") as RuntimeAnimatorController;
walking = false;
}
}
if (col.gameObject.tag == "Wall")
{
npcPrefab.transform.eulerAngles += new Vector3(0,180,0);
}
}
}