我正在做的事情是一个物体在平面上移动,而相机位于它的中心。我得到了它,所以相机随着鼠标旋转,当主相机看到游戏对象时,它会停止。所以我使用了 onbecamevisible() 和 onbecameinvisible() 函数,但这适用于任何相机,包括场景视图。如何使对象在仅被主游戏摄像机看到时停止?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class cubeMove : MonoBehaviour,moveObject
{
Camera cam;
public Transform checkedObject;
void Start()
{
cam = GetComponent<Camera>();
}
void Update()
{
Vector3 viewPos = cam.WorldToViewportPoint(checkedObject.position);
if ()
move();
}
public void move()
{
transform.Rotate(new Vector3(15, 30, 45) * Time.deltaTime);
}
Run Code Online (Sandbox Code Playgroud)
}
这是我的相机脚本
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Camera : MonoBehaviour {
public enum RotationAxes { MouseXAndY = 0, MouseX = 1, MouseY = 2 }
public …Run Code Online (Sandbox Code Playgroud) 我只是试图让观察者模式程序一个对象随机改变颜色并导致一组其他对象改变相同的颜色,但我希望它们在 5 秒内逐渐改变。我正在尝试 lerp,但它只是立即交换颜色。我想这可能与 lerp 的起始颜色有关,因为主要对象是不断变换颜色,新颜色变成旧颜色。所以我需要考虑如何为 lerp 选择一个起始颜色。我不确定这是否与我的 lerp 不工作有关,但这是我正在考虑的。如果其他人有任何建议,我将不胜感激。谢谢你。
public class Subject : MonoBehaviour {
public float timer = 0.0f;
public GameObject[] observers;
float t = 0;
Color oldColor;
void Update () {
t += Time.deltaTime / 5.0f;
timer += Time.deltaTime;
if (timer >= 10f) {
Color newColor = new Color(Random.value, Random.value, Random.value, 1.0f);
GetComponent<Renderer>().material.color = newColor;
for (int i = 0; i < observers.Length; i++) {
observers[i].GetComponent<Renderer>().material.color = Color.Lerp(oldColor, newColor, t);
}
newColor=oldColor
timer = 0;
}
} …Run Code Online (Sandbox Code Playgroud) 我在C#中开发了一个tic tac toe游戏并设置了胜利条件的功能,但我似乎无法弄清楚如何在网格满时设置条件.当我尝试输入时,领带会随机出现.我想知道是不是我如何设置or和and运算符.这就是我尝试过的.
public bool Ended()
{
if (grid[0, 0] == 'X' && grid[0, 1] == 'X' && grid[0, 2] == 'X') { Console.WriteLine("PLayer 1 Wins"); return true; }
if (grid[1, 0] == 'X' && grid[1, 1] == 'X' && grid[1, 2] == 'X') { Console.WriteLine("PLayer 1 Wins"); return true; }
if (grid[2, 0] == 'X' && grid[2, 1] == 'X' && grid[2, 2] == 'X') { Console.WriteLine("PLayer 1 Wins"); return true; }
if (grid[0, 0] == 'X' && grid[1, …Run Code Online (Sandbox Code Playgroud)