查看: 1992|回复: 0
打印 上一主题 下一主题

C#写的脚本,作用是鼠标拖动物体,但是出现了错误

[复制链接]

733

主题

5

听众

1万

积分

资深设计师

Rank: 7Rank: 7Rank: 7

纳金币
6520
精华
14

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

跳转到指定楼层
楼主
发表于 2013-6-29 15:57:56 |只看该作者 |倒序浏览
代码如下:
using System.Collections; public class clickmove : MonoBehaviour { // Use this for initialization
void Start () {

}

// Update is called once per frame
void Update () {

}
IEnumerator OnMouseDown()
{

Vector3 ScreenSpace = Camera.main.WorldToScreenPoint(transform.position);

Vector3 offset = transform.position-Camera.main.ScreenToWorldPoint(Vector3(Input.mousePosition.x,Input.mousePosition.y,ScreenSpace.z));

Debug.Log("down");


if(Input.GetMouseButton(0))
{

Vector3 curScreenSpace = Vector3(Input.mousePosition.x,Input.mousePosition.y,ScreenSpace.z);

Vector3 CurPosition = Camera.main.ScreenToWorldPoint(curScreenSpace)+offset;

transform.position = CurPosition;

//yield return new WaitForFixedUpdate();
}


}
}
错误提示:

Assets/script/clickmove.cs(20,65): error CS1502: The best overloaded method match for `UnityEngine.Camera.ScreenToWorldPoint(UnityEngine.Vector3)' has some invalid arguments

(Filename: Assets/script/clickmove.cs Line: 20) Assets/script/clickmove.cs(20,65): error CS1503: Argument `#1' cannot convert `object' expression to type `UnityEngine.Vector3'

(Filename: Assets/script/clickmove.cs Line: 20) Assets/script/clickmove.cs(28,50): error CS0119: Expression denotes a `type', where a `variable', `value' or `method group' was expected

(Filename: Assets/script/clickmove.cs Line: 28) Refresh, detecting if any assets need to be imported or removed ... 0.001411 seconds (Nothing changed)
分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

手机版|纳金网 ( 闽ICP备2021016425号-2/3

GMT+8, 2024-11-15 01:56 , Processed in 0.654312 second(s), 28 queries .

Powered by Discuz!-创意设计 X2.5

© 2008-2019 Narkii Inc.

回顶部