Recently,I was learning unity 3d, I want to make an object move a distance by C#,I don't know if I'm right,that's what I write:
using UnityEngine;
using System.Collections;
public class sceneTransform : MonoBehaviour {
public float speed=0.1f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(transform.position.z<7){
transform.position += new Vector3 (0.2,0,0)*speed*Time.deltaTime;
}
}
}
Vector3的参数必须为float。
transform.position += new Vector3 (0.2f,0,0) * speed * Time.deltatime;
Concerning the error:
Assets/Scripts/sceneTransform.cs(15,68): error CS1502: The best overloaded method match for "UnityEngine.Vector3.Vector3(float, float, float)" has some invalid arguments,and Assets/Scripts/sceneTransform.cs(15,68): error CS1503: Argument "#1 " cannot convert "double" expression to type "float"
When working with floats in Unity3D, you need to put an "f" after them, like:
Vector3(0.2f,0f,0f);
我总是只使用transform.Translate()
通常为我移动对象。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.