I converted this code from JavaScript to C#:
using UnityEngine;
using System.Collections;
public class SharpCubeMoveTwo : MonoBehaviour {
void Start (){
}
void Update (){
if (Vector3.Distance(GameObject.FindGameObjectWithTag("Player").transform.position,transform.position) < 5) {
transform.position = Vector3.MoveTowards(Vector3(0,0,0),Vector3(0,100,0),20) ;
}
}
}
I get these errors:
Assets/Standard Assets/Scripts/General Scripts/SharpCubeMoveTwo.cs(14,50): error CS0119: Expression denotes a type', where a
variable’, value' or
method group’ was expected
Assets/Standard Assets/Scripts/General Scripts/SharpCubeMoveTwo.cs(14,65): error CS0119: Expression denotes a type', where a
variable’, value' or
method group’ was expected
Assets/Standard Assets/Scripts/General Scripts/SharpCubeMoveTwo.cs(14,38): error CS1502: The best overloaded method match for `UnityEngine.Vector3.MoveTowards(UnityEngine.Vector3, UnityEngine.Vector3, float)’ has some invalid arguments
Assets/Standard Assets/Scripts/General Scripts/SharpCubeMoveTwo.cs(14,38): error CS1503: Argument #1' cannot convert
object’ expression to type `UnityEngine.Vector3’
So I tried adding the NEW keyword:
using UnityEngine;
using System.Collections;
public class SharpCubeMoveTwo : MonoBehaviour {
void Start (){
}
void Update (){
if (Vector3.Distance(GameObject.FindGameObjectWithTag("Player").transform.position,transform.position) < 5) {
transform.position = new Vector3.MoveTowards(Vector3(0,0,0),Vector3(0,100,0),20) ;
}
}
}
Now I get just one error:
Assets/Standard Assets/Scripts/General Scripts/SharpCubeMoveTwo.cs(14,42): error CS0426: The nested type MoveTowards' does not exist in the type
UnityEngine.Vector3’
The script won’t compile and I’m not sure what I’m doing wrong. I need help. I’m a n00b in both Javascript and C# so please use small words lol