- Home /
Enable Trigger On Trigger
var obj : GameObject;
function Start () {
obj.GetComponent.<Collider>().BoxCollider.Collider = false;
}
function OnTriggerEnter (other : Collider) {
if(other.gameObject.tag == "Player") {
obj.GetComponent.<Collider>().BoxCollider.IsTrigger = true;
obj.GetComponent.<Collider>().BoxCollider.Collider = true;
}
}
I wrote this script but it's not working, any suggestions? :(
What do you mean by "not working"? Are you getting compiler errors? Or is it not working at runtime?
You have a lot of issues in what you wrote. For one, you seem to be mixing C# and Js together. I suggest you learn a bit about program$$anonymous$$g and scripting in Unity before you go any further. I am afraid, based on what you have written so far, there is no way I could help you without writing your script for you. But you wouldn't learn that way, and that is not really the point of these forums. I suggest you start by learning a bit about program$$anonymous$$g in general, and then learn a bit about scripting in Unity. Pick one of the two languages and stick to it. Personally, I suggest C# since there is more Unity specific information and tutorials about it.
Here is a great site that can $$anonymous$$ch you the basic C# syntax: https://www.sololearn.com/Course/CSharp/
Here are the Unity scripting tutorials: https://unity3d.com/learn/tutorials/s/scripting
Now, someone might come along and try to write a script for you anyways, but believe me when I say that you are better off spending time learning how to code for yourself than you are trying to ask other people to write your game for you one script at a time. If you get stuck with something specific, be sure to let us know so we can help you out. But it is hard to help with a question that is so broad.
You can only create an empty object with a trigger collider, set it not active and when you want you can active it!
Answer by SharkoFR · May 01, 2018 at 07:30 PM
Hum, javascript is not currenlty used in unity.
As far as I am aware, unityscript (aka javascript) still works they've just removed the menu item. I don't think it is being removed until 2018.1 or 2018.2.
JavaScript works fine for me in some other scripts. But can you please write a C# suggestion? I'm a bit dumb for C# :(
Well this will take a long time :/ But thank you
Your answer
![](https://koobas.hobune.stream/wayback/20220612161841im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
OnTriggerEnter() is occasionally not occurred 1 Answer
How can i detect by script when a character enter a hole in object ? 1 Answer
In-Game Tutorial with special actions in special areas. (Shooter) 0 Answers
Can child game object with OnTriggerEnter function use parent game object's collider? 2 Answers
Void OnTriggerEnter not working 1 Answer