【发布时间】:2017-09-06 15:12:45
【问题描述】:
我想把物体的位置换成鼠标的位置,从第一个位置慢慢移动到第二个位置。
我的对象正在缓慢地向似乎与左下角相连的随机方向移动。当我高于拐角时,我的对象向上移动,左右相同。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Rocket : MonoBehaviour
{
public float speed = 10f;
private Vector3 shippos;
void Start()
{
shippos = transform.position;
}
void FixedUpdate()
{
if (Input.mousePosition.x > shippos.x)
shippos.x=shippos.x+speed*Time.deltaTime;
if (Input.mousePosition.x < shippos.x)
shippos.x=shippos.x-speed*Time.deltaTime;
if (Input.mousePosition.y > shippos.y)
shippos.y=shippos.y+speed*Time.deltaTime;
if (Input.mousePosition.y < shippos.y)
shippos.y=shippos.y-speed*Time.deltaTime;
transform.position = shippos;
}
}
【问题讨论】:
-
您似乎在问 3 个不同的问题。也不完全清楚你在这三者中想要达到的目标。您能否编辑您的问题,以便清楚您需要帮助完成什么。
-
@ryemoss 已编辑,也许现在更清楚了?