首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将unity3d移动更改为拖动时出错(c#)

将unity3d移动更改为拖动时出错(c#)
EN

Stack Overflow用户
提问于 2015-04-08 21:30:10
回答 1查看 85关注 0票数 0

我的错误是

  • 'UnityEngine.Collider2D‘是'type’,但使用起来像‘变量’
  • 最佳重载方法匹配“UnityEngine.Vector3.Vector3(浮点、浮点、浮点数)”有一些无效的参数
  • 参数“1”:不能从“双”转换为“浮动” 使用UnityEngine;使用System.Collections;公共类MoveRacket : MonoBehaviour {公共浮动速度= 30;公共字符串轴=“垂直”;公共对象球拍=“球拍”;公共bool touchInput = true;public Vector2 touchPos;FixedUpdate () {//用于括号内没有任何东西//浮点数v= Input.GetAxisRaw (轴);浮点数v= Input.GetAxisRaw (轴);GetComponent ().velocity =新的Vector2 (0,v) *速度;if (Input.touchCount == 1) { Vector3 wp =Vector3 Vector2 touchPos =新Vector2(wp.x,wp.y);if (Touch = Physics2D.OverlapPoint(touchPos)) { this.transform.position =新Vector3 (3.94,wp.y,0);}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-04-08 22:23:15

你这里有两个问题。首先,您试图将Collider2D结果Physics2D.OverlapPoint(touchPos)分配给Touch的统一结构类型。不太清楚你的意图是什么。如果您只想测试touchPos是否重叠,请使用以下代码:

代码语言:javascript
复制
public class MoveRacket : MonoBehaviour {
public float speed = 30;
public string axis = "Vertical";
public object racket = "Racket";
public bool touchInput = true;
public Vector2 touchPos;





void FixedUpdate () {

    //used to not have anything in parentheses
    //float v = Input.GetAxisRaw (axis);
    float v = Input.GetAxisRaw (axis);
    GetComponent<Rigidbody2D> ().velocity = new Vector2 (0, v) * speed;
    if (Input.touchCount == 1)
    {
        Vector3 wp = Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position);
        Vector2 touchPos = new Vector2(wp.x, wp.y);
        if (Physics2D.OverlapPoint(touchPos) != null)
        {
            this.transform.position =  new Vector3 (3.94f,wp.y,0);

    }
    }
}
}

另一个问题是,当vector3构造函数期望浮动时,值3.94被视为一个双数据类型。若要将其解释为浮点数,请在数字的末尾添加"f“。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29525713

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档