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? :frowning:

What do you mean by "not working"? Are you getting compiler errors? Or is it not working at runtime?

You can only create an empty object with a trigger collider, set it not active and when you want you can active it!

That does look to be working properly, although it would appear the view-to-world transformation isn't happening (again, I would imagine a bug in shader graph). In that case, I would suggest also providing the cameraToWorld matrix in the same way you provide the inverse projection matrix and multiply the point by that rather than using the transform node.

1 Answer

1

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# :(