Skip to main content
 首页 » 编程设计

c#之无法将类型 int' 隐式转换为 unityengine.vector3'

2024年02月05日15arxive

嗨,我是 unity 的新手,所以这是我的代码:

using UnityEngine; 
using System.Collections; 
 
public class NewBehaviourScript : MonoBehaviour { 
 
    // Use this for initialization 
    void Start () { 
 
    } 
 
    // Update is called once per frame 
    void Update () { 
 
        var pos = transform.position; 
        pos.x += 1; 
        transform.position = pos; 
        string ss = "hellow"; 
 
        if(pos>100){ 
            print (ss); 
        } 
    } 
} 

但在 if 条件行中给我这个错误:无法将类型 int 隐式转换为 unityengine.vector3'

请您参考如下方法:

transform.position 是 Vector3 类型。你应该在 if 条件下执行 pos.x > 100 而不是 pos > 100。