Hi! I want dispay my menu when the player dies (on collision) but I can’t.
Here my script attached to player:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMove : MonoBehaviour
{
private CharacterController controller;
private Vector3 direction;
public float forwardSpeed;
private int desiredLane = 1; // 0: left 1: middle 2:right
public float laneDistance = 4; // distance between two line
public float jumpForce;
public float Gravity = -20;
public bool isDead=false;
void Start ()
{
controller = GetComponent<CharacterController>();
}
void Update()
{
if (isDead)
return;
controller.Move(direction*Time.deltaTime);
direction.z = forwardSpeed;
if (controller.isGrounded)
{
direction.y = -1;
if(Input.GetKeyDown(KeyCode.UpArrow))
{
Jump();
}
} else
{
direction.y += Gravity * Time.deltaTime;
}
if(Input.GetKeyDown(KeyCode.RightArrow))
{
desiredLane++;
if (desiredLane==3)
desiredLane=2;
}
if(Input.GetKeyDown(KeyCode.LeftArrow))
{
desiredLane--;
if (desiredLane==-1)
desiredLane=0;
}
Vector3 targetPosition = transform.position.z * transform.forward + transform.position.y * transform.up;
if(desiredLane == 0)
{
targetPosition+= Vector3.left * laneDistance;
} else if (desiredLane==2)
{
targetPosition += Vector3.right * laneDistance;
}
transform.position = Vector3.Lerp(transform.position, targetPosition, 80*Time.deltaTime);
// controller.center = controller.center; //per far funzionare il collider correttamente
}
private void Jump()
{
direction.y = jumpForce;
}
public void OnControllerColliderHit(ControllerColliderHit hit)
{
if(hit.point.z > transform.position.z + controller.radius)
Destroy(gameObject);
// Death();
}
public void Death()
{
isDead = true;
}
}
Here my script attached to menu:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DeathMenu : MonoBehaviour
{
PlayerMove playerDead;
void Start()
{
gameObject.SetActive (false);
playerDead = gameObject.GetComponent<PlayerMove>();
}
void Update()
{
if (playerDead.isDead)
{
gameObject.SetActive (true);
}
}
}
Thanks for answering!