Question by
watercat · Mar 14, 2018 at 05:26 PM ·
2djavascriptchangefor
how I change this Js code for 2D
how I change this Js code for 2D
#pragma strict
var baritita : float;
var x : float;
var y : float;
var z : float;
function OnTriggerStay (other : Collider) {
if (other.attachedRigidbody)
other.attachedRigidbody.AddForce(Vector3(x, y, z) * baritita);
}
Comment
What you want to change. Explain your problem clearly. If you want to change OnTriggerStay then
#pragma strict
function OnTriggerStay2D(other: Collider2D) {
other.attachedRigidbody.AddForce(-0.1F * other.attachedRigidbody.velocity);
}
See the documentation https://docs.unity3d.com/ScriptReference/$$anonymous$$onoBehaviour.OnTriggerStay2D.html
Best Answer
Answer by tormentoarmagedoom · Mar 14, 2018 at 05:31 PM
Delete z variable, and use a Vector2
Yeah you dont even need to delete z. Just pack it manually. Its just simple remapping.
I found it thenx
#pragma strict
var baritita : float;
var x : float;
var y : float;
function OnTriggerStay2D (other : Collider2D) {
if (other.attachedRigidbody)
other.attachedRigidbody.AddForce(Vector2(x, y) * baritita);
}
JS/US is being discontinued. You should start switching to C#.