Hi I’m a beginner at coding and i’m trying to make a script so that when the Player enters a Collider a GUI text will come up and say “Press F to Destroy” and then when the Player presses F the GameObject will be destroyed. Can anyone help? (I prefer to use C#).
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Playerdestroy : MonoBehaviour {
Text text;
void OnCollisionStay(Collision col) {
if (col.gameObject.name == "player")
{
text.text ="Press F Key To Destroy The Player";
if(Input.GetKeyDown(KeyCode.F)) {
Destroy(gameObject);
}
}
}
}
You have create a text and choose the text in script.
And gameobject the player you have to change the name to = player
attach script to Collider that where player enters.