… For move smoothly to object position, the same code worked well in JS, but gave me error C# …:
Javascript Code:
var target : Transform;
function Update ()
{
transform.position = Vector3.Lerp(this.transform.position, Vector3(target.transform.position.x,target.transform.position.y,target.transform.position.z), 0.2);
}
C# Code:
public Transform target;
void Update ()
{
transform.position = new Vector3.Lerp(this.transform.position, new Vector3(target.transform.position.x,target.transform.position.y,target.transform.position.z), 0.2);
}
Console C# Errors:
error CS0426: The nested type `Lerp' does not exist in the type `UnityEngine.Vector3'
ok…, i removed new keyword from Vector3.Lerp method, there are more errors:
The Code:
using UnityEngine;
using System.Collections;
public class NewBehaviourScript1 : MonoBehaviour {
public Transform target;
// Update is called once per frame
void Update () {
transform.position = Vector3.Lerp(this.transform.position, new Vector3(target.transform.position.x,target.transform.position.y,target.transform.position.z), 0.2);
}
}
The Console:
error CS1502: The best overloaded method match for `UnityEngine.Vector3.Lerp(UnityEngine.Vector3, UnityEngine.Vector3, float)' has some invalid arguments
error CS1503: Argument `#3' cannot convert `double' expression to type `float'