Мне нужна помощь с моим кодом, я новичок, работающий над небольшим проектом.using System;
using System.Linq;
using Unity.VisualScripting;
using Unity.VisualScripting.FullSerializer;
using UnityEngine;
using UnityEngine.Animations;
using UnityEngine.InputSystem.XR;
// This program is used to move the camera to different positions in the scene
public class MoveCamera : MonoBehaviour
{
// This get transform points that the camera will go to
public Transform[] CamsPositions;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
CamsPositions.Append(GameObject.Find("CamPos1").transform);
CamsPositions.Append(GameObject.Find("CamPos2").transform);
// used to find the transform and put them in the array
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.E))
{
MoveCam(CamsPositions[0]);
}
if (Input.GetKeyDown(KeyCode.A))
{
MoveCam(CamsPositions[1]);
}
}
public void MoveCam(Transform position)
{
transform.position = position.position;
}
}
< /code>
Я пытаюсь сделать механик, который переключает положение камеры в сцене, она работает нормально, но каждый раз, когда я нажимаю на ключи, я получаю ошибку «индекс вне границ». Я не знаю, почему, так что любая помощь действительно ценится
Подробнее здесь: https://stackoverflow.com/questions/797 ... -transform