(Perdón por mi inglés, soy español)
Hello, I was making a videogame for slenderman with all their respective codes until when my slenderman touches my character it doesn’t detect it with the panelend or gameover with textpro instead if it works for the house (cabin) that is integrated with private void OnTriggerEnter( Collider other), but unlike Slenderman using private void OnCollisionEnter(Collision collision) once the player is touched nothing happens and I would like to know if something is missing or what to add because I can’t find it.
Points to consider:
-the RigidBodyFPSController is labeled “Player”
-Slenderman uses navmesh to chase the player.
-The house(cabin) with “private void OnTriggerEnter(Collider other)” works with a collider once it is already in place.
-The player is being used with rigidbody.
-The panelend should work for both slenderman and the cabin, however when the slenderman touches the player it is not detected.
-I have no problems on the console.
my problem “guide” (video):
I’ll leave screenshots and codes here.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class SlenderMan : MonoBehaviour
{
private Transform objetivo;
private NavMeshAgent agente;
private GameManager gameManager;
private void Awake()
{
objetivo = GameObject.FindGameObjectWithTag("Player").transform;
agente = GetComponent<NavMeshAgent>();
gameManager = FindObjectOfType<GameManager>();
}
private void Start()
{
StartCoroutine(tiempoDestruccion());
}
private void Update()
{
agente.SetDestination(objetivo.position);
}
private void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.CompareTag("Player"))
{
gameManager.Aparecefinal("Has Muerto");
}
}
private IEnumerator tiempoDestruccion()
{
for (int i = 0; i < 15; i++)
{
yield return new WaitForSeconds(1);
}
gameManager.CrearNuevoSlender();
Destroy(this.gameObject);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Casa : MonoBehaviour
{
[SerializeField] GameManager gameManager;
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag(“Player”))
{
gameManager.Aparecefinal(“A salvo”);
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using UnityEngine.SceneManagement;
public class GameManager : MonoBehaviour
{
[SerializeField] GameObject slender;
[SerializeField] GameObject personaje;
[SerializeField] Transform[ ] arrayPuntosSalida;
[SerializeField] GameObject panelFinal;
[SerializeField] private TextMeshProUGUI textoFinal;
private int puntoSalida;
private void Start()
{
EstablecerPunto(personaje);
CrearNuevoSlender();
}
private void EstablecerPunto(GameObject objeto)
{
puntoSalida = Random.Range(0, arrayPuntosSalida.Length);
objeto.transform.position = arrayPuntosSalida[puntoSalida].position;
}
public void CrearNuevoSlender()
{
Instantiate(slender);
EstablecerPunto(slender);
}
public void Botones(bool eleccion)
{
if (eleccion == true)
{
SceneManager.LoadScene(0);
}
else
{
Application.Quit();
}
}
public void Aparecefinal(string texto)
{
panelFinal.SetActive(true);
textoFinal.text = texto;
}
}