Added enemy models
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
namespace InterfaceOff.WorldScene
|
||||
{
|
||||
@@ -6,9 +8,53 @@ namespace InterfaceOff.WorldScene
|
||||
{
|
||||
[SerializeField] private PlayerController Player;
|
||||
[SerializeField] private int DeathIndex = 500;
|
||||
[SerializeField] private GameObject Renderer;
|
||||
[SerializeField] private Rigidbody Body;
|
||||
[SerializeField] private GameObject RendererObject;
|
||||
|
||||
private void Update() =>
|
||||
Renderer.SetActive(DeathIndex > Player.FrameIndex);
|
||||
private Quaternion StartRotation;
|
||||
private Vector3 StartPosition;
|
||||
|
||||
private bool WasAliveLastFrame;
|
||||
private bool Alive = true;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
StartPosition = transform.position;
|
||||
StartRotation = transform.rotation;
|
||||
|
||||
Body.Sleep();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
/* Updates the death state */
|
||||
WasAliveLastFrame = Alive;
|
||||
Alive = DeathIndex >= Player.FrameIndex;
|
||||
|
||||
/* Checks if it just died */
|
||||
if (!Alive && WasAliveLastFrame)
|
||||
{
|
||||
Body.WakeUp();
|
||||
Body.AddForce(Random.insideUnitSphere * 250);
|
||||
|
||||
StartCoroutine(routine: Suicide());
|
||||
}
|
||||
|
||||
if (Alive)
|
||||
{
|
||||
transform.position = StartPosition;
|
||||
transform.rotation = StartRotation;
|
||||
Body.velocity = Vector3.zero;
|
||||
|
||||
RendererObject.SetActive(true);
|
||||
Body.Sleep();
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator Suicide()
|
||||
{
|
||||
yield return new WaitForSeconds(1f);
|
||||
RendererObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user