This commit is contained in:
Rizvee committed 2022-02-25 01:00:32 -06:00
1 parent e62fe6ec5f
commit 14c81c67d6
9 files changed
+1376 -43

No files matched your search

+30 -11
View File
@@ -8,27 +8,46 @@ public class NPC : MonoBehaviour
{
public Movement controller;
float horizontalMove = 0f;
public float runSpeed = 40f;
public string title = "";
public Animator animator;
float horizontalMove = 1f;
public float runSpeed = 20f;
public float leftBound;
public float rightBound;
float elapsed;
public float minDelay;
public float maxDelay;
float delay;
//constructs an NPC using parameters
public NPC(string name, float run, float hor)
{
title = name;
runSpeed = run;
horizontalMove = hor;
}
void Start()
{
delay = Random.Range(minDelay, maxDelay);
horizontalMove = horizontalMove * runSpeed;
}
// Update is called once per frame
void Update()
{
if(elapsed > delay) {
horizontalMove = -1 * (horizontalMove/Mathf.Abs(horizontalMove)) * runSpeed;
elapsed = 0f;
delay = Random.Range(minDelay, maxDelay);
}
if(Movement.pause) {
animator.SetFloat("Horizontal", 0);
}
if (animator != null && !Movement.pause) {
animator.SetFloat("Horizontal", (horizontalMove/Mathf.Abs(horizontalMove)));
animator.SetBool("Airborne", !controller.m_Grounded);
}
elapsed += Time.deltaTime;
if(transform.position.x > rightBound) {
horizontalMove = -1 * runSpeed;
}
if(transform.position.x < leftBound) {
horizontalMove = runSpeed;
}
}
//NPC movement determined by script in subclasses
+4 -1
View File
@@ -24,7 +24,10 @@ public class PlayerMovement : MonoBehaviour
} else if (Input.GetKeyUp(KeyCode.LeftShift)) {
crouch = false;
}
if(Movement.pause) {
animator.SetFloat("Horizontal", 0);
}
if (animator != null && !Movement.pause) {
animator.SetFloat("Horizontal", Input.GetAxis("Horizontal"));
animator.SetBool("Airborne", !controller.m_Grounded);