Hello! I’m making an endless runner game, and it is made for the character to change directions of movement multiple times. And i got it to work to change the direction of the movement once but it doesn’t want to change multiple times. Please help me and be specific (write the code)
Here is the movement code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class PlayerMovement : MonoBehaviour
{
private CharacterController controller1;
private float speed = 5.0f;
private Vector3 direction = Vector3.right;
// Use this for initialization
void Start()
{
controller1 = GetComponent<CharacterController>();
}
// Update is called once per frame
void Update()
{
controller1.Move(direction * Time.deltaTime * speed);
}
}
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Turn") ;
{
transform.rotation = Quaternion.Euler(0, 0, 0);
direction = Vector3.zero;
}
if (other.gameObject.tag == "Turn1") ;
{
transform.rotation = Quaternion.Euler(0,90, 0);
direction = Vector3.zero;
Debug.Log("z");
}
if (other.gameObject.tag == "Turn2") ;
{
transform.rotation = Quaternion.Euler(0, 180, 0);
direction = Vector3.left;
}
if (other.gameObject.tag == "Turn3") ;
{
transform.rotation = Quaternion.Euler(0, 270, 0);
direction = Vector3.forward;
}
}
}
It’s actually part of it. Please help me i can’t figure this out.
Thanks in advance.