Answer the question
In order to leave comments, you need to log in
Need help fixing Unity script in C#. Who understands?
Good day to all. The question is. You need to write a script, the main function of which is that when you enter the trigger object to which this script is attached, and when the player presses a key on the keyboard (for example, E), this trigger object is deleted. Here is my experience, but for some reason it doesn't work:
using UnityEngine;
using System.Collections;
public class radio : MonoBehaviour
{
void OnTriggerEnter(Collider other)
{
Debug.Log("Trigger");
if (Input.GetKey(KeyCode.E))
{
Destroy(gameObject);
Debug.Log("Button");
}
}
Answer the question
In order to leave comments, you need to log in
void OnTriggerEnter(Collider other)
fires at the moment of collision of trigger colliders. And pressing the keyboard key occurs at a different moment. It doesn't work, although not always. Usually such things are written in Update
.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question