What ways are there to make a if statement that ask the question “if object1 position equals object2 position do this if else do that”? I am more specifically having troubles with my code:
#pragma strict
var Target : Transform;
var Distance = -10;
var Lift = 1.5;
var script: TriggerCam1;
var parget: Transform;
var speed: float;
var CamChange = 0;
var speedt: float;
var pargett: Transform;
var endcut : Transform;
var cam : Transform;
function Update ()
{
if (CamChange == 1)
{
var step = speed * Time.deltaTime;
transform.position = Vector3.MoveTowards(transform.position, parget.position, step);
}
else
if (CamChange == 2)
if (cam.position == endcut.position) //I know this doesn't work, but it's to help show what I need.
{
CamChange == 0;
}
else
{
var stept = speedt * Time.deltaTime;
transform.position = Vector3.MoveTowards(transform.position, pargett.position, stept);
}
else
{
transform.position = Target.position + Vector3(0, Lift, Distance);
transform.LookAt(Target);
}
}
under CamChange == 2 it has the if statement. that is where i need help. I dont know how to make that type of if statement.
I don't know what your talking about for the first thing (about the legibility) but I'll try your code to see if it works.thanks! (Maybe)
– AAcatkeep getting this error: Assets/Scripts/CameraScriptv2.js(29,43): BCE0034: Expressions in statements must only be executed for their side-effects.
– AAcatoh i figured it out. There was == instead of =. The code works fine now thanks.
– AAcatConcerning the performance part, I think Vector3.Distance is actually faster than sqrMagnitude, due to the fact it is done on the native side. To be confirmed.
– fafase