【发布时间】:2017-09-10 12:27:21
【问题描述】:
所以我试图创造一种像坦克一样的炮台。上半部分需要看我的鼠标。我试过了
GetComponent().ScreenToWorldPoint(Argument);
很多时候在一起
Input.mousePosition();
但我真的想不通。如果有人可以提供帮助或提供一个可以在 3D 环境中工作的简单脚本,我将在 C# 中对此进行编程,这将是很棒的!
到目前为止我的代码:
using UnityEngine;
using System.Collections;
public class Laser : MonoBehaviour {
public float Speed;
public AudioClip LaserSFX;
private Transform Player;
public Vector3 mousePos;
public Camera Cam;
// Use this for initialization
void Start () {
GameObject player = GameObject.FindWithTag("Player");
Player = player.transform;
if(!GetComponent<AudioSource>().isPlaying)
GetComponent<AudioSource> ().PlayOneShot (LaserSFX);
}
// Update is called once per frame
void Update () {
//Code to look at mouse or rotate
//Code to move towards it
float dist = Vector3.Distance(Player.position, transform.position);
if (dist >= 500)
{
Destroy(gameObject);
}
}
}
致以诚挚的问候,
Misterk99
【问题讨论】:
-
你能澄清一下这个问题吗?您的疑问是如何获得鼠标的坐标或旋转算法?
-
我要做的就是拿到鼠标的绳子,然后将对象朝它旋转。由于我的相机旋转到自上而下的视图,mouse.y 轴是世界空间中的 z 轴。