Code for random encounter:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class RandomEncounter : MonoBehaviour
{
private int randomnumber = Random.Range(0, 10);
private const int maxnum = 10;
void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Player"))
{
if (randomnumber == maxnum)
{
SceneManager.LoadScene(sceneName: "Battle");
}
else
{
randomnumber = Random.Range(0, 10);
}
}
}
}
Code for player controller
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;
public class APlayer : MonoBehaviour
{
public float movementSpeed = 10;
public float turningSpeed = 100;
void Update()
{
float horizontal = Input.GetAxis(“Horizontal”) * turningSpeed * Time.deltaTime;
transform.Rotate(0, horizontal, 0);
float vertical = Input.GetAxis("Vertical") * movementSpeed * Time.deltaTime;
transform.Translate(0, 0, vertical);
}
}
There is no other defined variables that could interrupt and I do not know what could be the problem