Fehler in der Array -Transformation "Index aus den Grenzen"C#

Ein Treffpunkt für C#-Programmierer
Anonymous
 Fehler in der Array -Transformation "Index aus den Grenzen"

Post by Anonymous »

Ich brauche Hilfe bei meinem Code, ich bin ein Anfänger, der an einem kleinen Projekt arbeitet.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>
Ich versuche, einen Mechaniker zu machen, der die Kameraposition in der Szene umschaltet. Es funktioniert gut, aber jedes Mal, wenn ich die Schlüssel drücke, erhalte ich einen "Index aus den Grenzen". Ich weiß jedoch nicht warum, also ist jede Hilfe wirklich geschätzt

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post