【发布时间】:2020-06-24 10:48:27
【问题描述】:
我是 Unity 初学者。 我的脚本有问题:在上图中,移动脚本中不存在播放器项目。
这是我的代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Move : MonoBehaviour
{
public float speed;
public Transform player;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
float x = Input.GetAxis("Horizontal");
float y = Input.GetAxis("Vertical");
transform.Translate(x * speed * Time.deltaTime, y * speed * Time.deltaTime, 0);
Vector2 v2 = Camera.main.ScreenToWorldPoint(Input.mousePosition) - player.position;
player.rotation = Quaternion.Euler(0, 0, Mathf.Atan2(v2.y, v2.x) * Mathf.Red2Deg);
}
}
【问题讨论】:
-
您使用的是什么版本的 Unity、操作系统和 IDE?另外,您是否确保在添加
public Transform player;后保存了脚本?