Conveyor and Patrol task (using Mathf.Repeat and Mathf.PingPong)

Squadico

Administrator
Staff member
Task: Implement conveyor and patrol tasks for npc

Conveyor and Patrol task code example
Original blog post (in Russian)

C#:
using UnityEngine;

public class ConveyorScript : MonoBehaviour
{
    int distance = 5;
   
    void Update ()
    {
        transform.position = new Vector3(Mathf.Repeat(Time.time, distance), transform.position.y, transform.position.z);
    }
}
C#:
using UnityEngine;

public class PatrolScript : MonoBehaviour
{
    float speed = 1;
    float distance = 5;
    void Update ()
    {
        transform.position = new Vector3(Mathf.PingPong(Time.time * speed, distance), transform.position.y, transform.position.z);
    }
}
 
Top