Question by
Harryhyman · Jan 29 at 06:40 PM ·
player movementrespawn
How to make player die/respawn on endless runner 3D game
Hi there,
I am making a endless runner game for my uni project and need my player to die when it comes off of the edge of the tiles they are running on. I have looked around for a solution but cant find one.
Does anyone know how make my player die/respawn in this way. I presume it would need to be coded into my player movement script which I have attached.
Thanks`
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class PlayerMovement : MonoBehaviour
{
private bool turnLeft, turnRight;
public float speed = 7.0f;
private CharacterController myCharacterController;
public GameObject textObject;
public int scoreCounter = 0;
//Audio Events
public AK.Wwise.Event coinCollectBeep = null; //Audio
public AK.Wwise.Event Play_Footstep_Cobble = null; //Audio
public AK.Wwise.Event Play_Footstep_Concrete = null; //Audio
public AK.Wwise.Event Play_Footstep_Grass = null; //Audio
// Start is called before the first frame update
void Start()
{
myCharacterController = GetComponent<CharacterController>();
}
// Update is called once per frame
void Update()
{
turnLeft = Input.GetKeyDown(KeyCode.A);
turnRight = Input.GetKeyDown(KeyCode.D);
if (turnLeft)
transform.Rotate(new Vector3(0f, -90f, 0f));
else if (turnRight)
transform.Rotate(new Vector3(0f, 90f, 0f));
myCharacterController.SimpleMove(new Vector3(0f, 0f, 0f));
myCharacterController.Move(transform.forward * speed * Time.deltaTime);
}
private void OnTriggerEnter(Collider other)
{
if(other.gameObject.CompareTag("PickUp"))
{
coinCollectBeep.Post(gameObject); //Audio
other.gameObject.SetActive(false);
scoreCounter = scoreCounter + 1;
textObject.GetComponent<Text>().text = "Score : " + scoreCounter;
}
}
public void PlayFootstepSound()
{
Play_Footstep_Cobble.Post(gameObject);
}
}
`
Comment
Your answer

Follow this Question
Related Questions
When touching ResSpawn C# Script 0 Answers
Problem with UNET calling methods 0 Answers
Why does my character keep respawning in the same place it dies? 0 Answers
2 Issues with my SHUMP game 0 Answers
my player wont move anymore 0 Answers