【发布时间】:2016-07-28 05:42:23
【问题描述】:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Waypoints : MonoBehaviour {
public Transform[] waypoint;
public float patrolSpeed;
public bool loop = true;
public int dampingLook = 4;
public float pauseDuration;
private float curTime;
private int currentWaypoint = 0;
public CharacterController character;
// Use this for initialization
void Start () {
}
void LateUpdate(){
if(currentWaypoint < waypoint.Length){
patrol();
}else{
if(loop){
currentWaypoint= 0;
}
}
}
void patrol(){
Vector3 nextWayPoint = waypoint[currentWaypoint].position;
// Keep waypoint at character's height
nextWayPoint.y = transform.position.y;
// Get the direction we need to move to
// reach the next waypoint
Vector3 moveDirection = nextWayPoint - transform.position;
transform 是字符的意思吗?所以在这种情况下,transform.position 将获得角色位置 ThirdPersonController 我添加了脚本吗?脚本如何知道变换属于角色?
如果我在做 Transform _transform 那么 _transform 和我现在使用的 transform 有什么区别?
如果我想设置或获取字符起始位置,例如我可以在脚本中创建:public Transform _transform;然后在启动函数中:_transform = GetComponent();那么例如我可以从 _transform 获得位置?
【问题讨论】:
-
不要用不相关的标签标记您的问题。
-
真的,SO 不是一个以“教程”为导向的网站。
-
无论出于何种原因,从不使用包括下划线在内的变量名。
-
@Joe 不同意,这是个人喜好。我所知道的所有词法分析器也都支持它。可能有他们说您不应该使用下划线的最佳实践。但请注意,还有一些使用下划线的最佳做法。
-
嗨,Nöel,刚刚待定,我专门针对 OP,TheLostLostit。 TheLostLostit,无论出于何种原因,您都不应该使用包括下划线在内的变量名。这在 Unity 中完全无关紧要,特别是如果您显然只是一个初学者,甚至不知道什么是 Transform v. transform 。所以,享受 - 但没有下划线! :)