Hello all, I am trying to create a “zoom” function when a prefab is clicked on (in another script, it places multiple ones in a row on the screen, named obj0, obj1, etc). There are a few major problems I am having, perhaps someone could help me out in fixing/understanding it? Questions are comments in the script starting with Q:
Code’s unityscript
var endPoint : Vector3;
endPoint = Vector3 (15.5, 26.75, 15);
// Q: I do not know why I need to declare endPoint and assign a value on different lines, but it won't change the values in the instantiated prefabs if I don't
var startPoint : Vector3;
var isMoving : boolean;
function Update () {
var hit : RaycastHit;
var itsaray : Ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast (itsaray, hit) Input.GetMouseButtonDown(0) !isMoving) {
var transform : Transform = hit.collider.GetComponent(Transform);
// Q: I do not know what the variable has to be 'transform'. I tried changing it in this line and the line below, and it wouldn't work. Care to explain?
if (transform) {
startTime = Time.time;
startPoint = transform.position;
// Q: Changing these three variables sets all the instantiated prefabs to these values, rather than just the one tested
isMoving = true;
}
}
if (isMoving) {
transform.position = Vector3.Lerp(startPoint, endPoint, Time.time - startTime);
// Q: Two problems, one I can't call variables startPoint/endPoint beause they don't have a reference, and two if I tweak it so it does work the jump happens instantly; how can I slow this down to take X time?
}
if (transform.position == endPoint) {
// Q: This call doesn't work at all, for the same reasons as Lerp didn't work earlier.
isMoving = false;
}
}
I’m new to unityscript so a few of these might be obvious but I couldn’t find any real answers online to this varibale question, so thanks in advance!