Question by
Wesley21spelde · Oct 29, 2016 at 04:34 PM ·
c#playerontriggerenternot working
My Turrent Trigger does not work
Hey guys my script does not do enything end it does not give a bug
i dont know what i did wrong Can You Help Me?.
using UnityEngine;
using System.Collections;
public class SwitchGunTurrent : MonoBehaviour
{
public GameObject Player; // The player is taged Player.
public GameObject Turrent; // The Gun Turremt With 2 GameObjects The Turrent its Self and The Player Turrent.
public GameObject On_turrent; // The Player Turrent.
void Start()
{
Player = GameObject.FindWithTag("Player");// Find Player
Player.SetActive(true);
On_turrent.SetActive(false);
}
void Update()
{
}
void OnTriggerEnter(Collision col) // Enter The Turrent OnTriggerEnter And GetKeyDown E. When GetKey E for the Secondtime Switch Back To The Player?.
{
if (col.gameObject.name == "Player")
{
if (Input.GetKeyDown(KeyCode.E))
{
On_turrent.SetActive(true);
Player.SetActive(false);
}
else if (On_turrent == true)
{
On_turrent.SetActive(false);
Player.SetActive(true);
}
}
}
}
Comment
Answer by OutOfRam · Oct 29, 2016 at 04:40 PM
Ok, This is simple, you used on trigger enter, which only fires once per enter, so it oes not have time to get the button pressed. Try using OnTrigger Stay
I hope This helps
Your answer
![](https://koobas.hobune.stream/wayback/20220612095644im_/https://answers.unity.com/themes/thub/images/avi.jpg)