I have a monster script and I cannot make it work, please help me find a better script.
- I want the monster to always look at the camera and use a
Rigidbody
.
MonsterScript.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class MonsterScript : MonoBehaviour
{
private Rigidbody MyBody;
public float MonsterSpeed;
void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.tag == "Player")
{
GameOver();
}
}
void Start()
{
MyBody = GetComponent<Rigidbody>();
}
void Update()
{
transform.LookAt(Camera.main.transform.position, -Vector3.up);
MyBody.velocity = transform.forward * Time.deltaTime * MonsterSpeed;
}
void GameOver()
{
Debug.Log("You've died...");
SceneManager.LoadScene("Menu");
SceneManager.UnloadSceneAsync("Menu Scene");
}
}
If you find a better solution tell me!