我在名为Fly Camera的相机上附加了3个脚本。 有点长,但是所有三个脚本都可以一起工作:
首先是脚本LookAtCamera:
}
下一个FlyToOverTerrain:
var UserChoice = window.prompt("Select rock, paper, or scissors");
var computChoice = Math.random();
if (computChoice <= 0.33) {
computChoice = "scissors";
} else if (computChoice <= 0.66 && computChoice > 0.33) {
computChoice = "paper";
} else {
computChoice = "rock";
}
if (UserChoice === "paper") {
if (UserChoice === "paper" && computChoice === "rock") {
window.alert("You chose paper and the computer chose rock! You win! Paper covers rock");
} else if (UserChoice === "paper" && computChoice === "paper") {
window.alert("It's a tie!");
} else if (UserChoice === "paper" && computChoice === "scissors") {
window.alert("You lose! You chose paper and computer chose scissors. Scissors cut paper!");
}
} else if (UserChoice === "scissors") {
if (UserChoice === "scissors" && computChoice === "paper") {
window.alert("You chose scissors and the computer chose paper! You win! Scissors cut paper.");
} else if (UserChoice === "scissors" && computChoice === "scissors") {
window.alert("It's a tie! You chose scissors and the computer chose scissors!");
} else if (UserChoice === "scissors" && computChoice === "rock") {
window.alert("You lose! You chose scissors and computer chose rock. Rock smashes scissors!");
}
} else if (UserChoice === "rock") {
if (UserChoice === "rock" && computChoice === "scissors") {
window.alert("You chose rock and the computer chose scissors! You win! Rock smashes scissors.");
} else if (UserChoice === "rock" && computChoice === "rock") {
window.alert("It's a tie! You chose rock and the computer chose rock!");
} else if (UserChoice === "scissors" && computChoice === "rock") {
window.alert("You lose! You chose rock and computer chose paper. Paper covers rock!");
} else {
window.prompt("Invalid choice! Choose from rock, paper, or scissors");
}
}
最后一次巡逻:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LookAtCamera : MonoBehaviour
{
//values that will be set in the Inspector
public Transform target;
public float RotationSpeed;
//values for internal use
private Quaternion _lookRotation;
private Vector3 _direction;
// Update is called once per frame
void Update()
{
//find the vector pointing from our position to the target
if (target)
_direction = (target.position - transform.position).normalized;
//create the rotation we need to be in to look at the target
if (_direction != Vector3.zero)
_lookRotation = Quaternion.LookRotation(_direction);
//rotate us over time according to speed until we are in the required rotation
transform.rotation = Quaternion.Slerp(transform.rotation, _lookRotation, Time.deltaTime * RotationSpeed);
}
}
摄像头面向第一个航路点旋转,但从不移动到下一个航路点。 有4个球体作为路标,它们被标记为目标。 在运行游戏时,相机会朝着第一个Sphere的方向缓慢平稳地旋转,然后停在那里,再也不会继续。它应该在所有球体之间移动,然后重新开始。
答案 0 :(得分:1)
我认为问题出在
if (targetOffset.sqrMagnitude <= sqrDistance)
{
flyOverTerrain.target = null;
lookAtCamera.target = null;
lingerDuration -= Time.deltaTime;
}
else
{
flyOverTerrain.target = patrol.target;
lookAtCamera.target = patrol.target;
}
您只需减少lingerDuration
一次,即到达第一个目标的帧。
所以您的
if (lingerDuration <= 0)
可能永远不会匹配。
我猜你想在Update
运行的每一帧中减少它,而是将其移动到该块之外。
我还建议宁可使用
if(Vector3.Distance(transform.position, patrol.target.position) <= patrol.minDistance)