mirror of
https://github.com/frizbee19/FebGameJam.git
synced 2026-11-11 04:22:40 +00:00
did a minor tweak
This commit is contained in:
1 parent
8f2a693284
commit
11a2af2f5f
302 files changed
+1022
-167
No files matched your search
@@ -0,0 +1,60 @@
|
||||
//WIP
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class NPC : MonoBehaviour
|
||||
{
|
||||
|
||||
public Movement controller;
|
||||
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
|
||||
|
||||
void Start()
|
||||
{
|
||||
delay = Random.Range(minDelay, maxDelay);
|
||||
horizontalMove = horizontalMove * runSpeed;
|
||||
leftBound += controller.transform.localPosition.x;
|
||||
rightBound -= controller.transform.localPosition.x;
|
||||
}
|
||||
|
||||
// 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.localPosition.x > rightBound) {
|
||||
horizontalMove = -1 * runSpeed;
|
||||
} else
|
||||
if(transform.localPosition.x < leftBound) {
|
||||
horizontalMove = runSpeed;
|
||||
}
|
||||
}
|
||||
|
||||
//NPC movement determined by script in subclasses
|
||||
void FixedUpdate()
|
||||
{
|
||||
controller.Move(horizontalMove *Time.fixedDeltaTime, false, false);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user