I simply want to move an object here is my code:
But it doesn’t work, every time i use Time.deltaTime in the script the position coordinates of the game object are not like the values in the variable. The position change to something else which is not insight of the camera.
Here is the hole script which is attached to the object:
using UnityEngine;
using System.Collections;
public class detailzoom_alaska : MonoBehaviour {
Vector3 karten_position = new Vector3(0.9578142f,0.2050258f, -0.0404333f);
Vector3 ausserhalb_karte_position = new Vector3(0.03719311f,0.3353992f, 0.008037157f);
public float smooth=1;
private static GameObject clickedGmObj2;
GameObject GetClickedGameObject()
{
// Builds a ray from camera point of view to the mouse position
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
// Casts the ray and get the first game object hit
if (Physics.Raycast(ray, out hit, Mathf.Infinity))
return hit.transform.gameObject;
else
return null;
}
void PositionChanging ()
{
if(Input.GetMouseButtonDown(0))
{
clickedGmObj2 = GetClickedGameObject();
if(clickedGmObj2)
{
if (clickedGmObj2.name=="alaska")
{
Vector3 neue_position = ausserhalb_karte_position;
transform.position = Vector3.Lerp(transform.position, neue_position, smooth * Time.deltaTime);
}
}
}
if(Input.GetMouseButtonDown(1))
{
clickedGmObj2 = GetClickedGameObject();
if(clickedGmObj2)
{
if (clickedGmObj2.name=="alaska")
{
Vector3 neue_position = karten_position;
transform.position = Vector3.Lerp(transform.position, neue_position, smooth * Time.deltaTime);
}
}
}
}
// Update is called once per frame
void Update ()
{
PositionChanging();
}
}
Does anyone have an idea why this code isn’t working ?
If i use instead a code with position change without lerp it works without errors, but i think lerp is a cool thing and i want to use it
Flo