RuneShiStorm
❔ How to play animation from a [ ] ?
Is this possible? Can I make a [] <I don't know what they are called...) function on an Animator Component and play an Animation based on its Name by typing the Name inside the inspector? If that make sense... For example, if a cat walk across the room, once it hits a boxcollider, it should play whatever is written inside Elemet0 [ ] - then the cat keeps walking and hit another boxcollider and play whatever is written inside Element1[] etc etc...
Thankful for answers!
6 replies
❔ How to make it NOT random and follow a Transform[]
Hello, new here and hope to get some help/pointers on what to do here.
I have made a script where my NPC can walk to different positions and wait for a sec, before moving on. But it walks to RANDOM positions... I can't find ANY tutorial on how to make an NPC go to each spot in order. And wait...
This is my Script:
[CODE]
public class patrolScript : MonoBehaviour
{
public float speed;
private float waitTime;
public float startWaitTime;
public Transform[] moveSpots;
private int randomSpot;
// Start is called before the first frame update
void Start()
{
waitTime = startWaitTime;
randomSpot = Random.Range(0, moveSpots.Length);
}
// Update is called once per frame
void Update()
{
transform.position = Vector2.MoveTowards(transform.position, moveSpots[randomSpot].position, speed * Time.deltaTime);
if(Vector2.Distance(transform.position, moveSpots[randomSpot].position) < 0.2f)
{
if(waitTime <= 0)
{
randomSpot = Random.Range(0, moveSpots.Length);
waitTime = startWaitTime;
}
else
{
waitTime -= Time.deltaTime;
}
}
}
}
[/CODE]
21 replies