by Anonymous » 17 Jan 2025, 10:19
Ich versuche, einen VR-Shooter zu erstellen, aber als ich mich eines Tages anmeldete, hatte die Komponente „FireBulletOnActivate“ meiner Waffe eine „Fehler“-Meldung. Normalerweise gibt es drei Optionen: eine für das Geschossmodell, eine für den Geschoss-Spawnpunkt und eine für die Bullet-Geschwindigkeit und und ich weiß nicht, wie ich das beheben kann. Könnte mir jemand helfen? Ich bin neu im Codieren und verwende Visual Studio mit Unity. Ich habe ein YouTube-Tutorial befolgt. Das ist mein Code:
Code: Select all
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR.Interaction.Toolkit;
public class FireBulletOnActivate : MonoBehaviour
{
public GameObject bullet;
public Transform spawnPoint;
public float fireSpeed = 20;
// Start is called before the first frame update
void Start()
{
XRGrabInteractable grabbable = GetComponent();
grabbable.activated.AddListener(FireBullet);
}
// Update is called once per frame
void Update()
{
}
public void FireBullet(ActivateEventArgs arg)
{
GameObject spawnedBullet = Instantiate(bullet);
spawnedBullet.transform.position = spawnPoint.position;
spawnedBullet.GetComponent().velocity =
spawnPoint.forward * fireSpeed;
Destroy(spawnedBullet, 5);
}
}
Das Video, dem ich gefolgt bin, ist hier--->
Ich versuche, einen VR-Shooter zu erstellen, aber als ich mich eines Tages anmeldete, hatte die Komponente „FireBulletOnActivate“ meiner Waffe eine „Fehler“-Meldung. Normalerweise gibt es drei Optionen: eine für das Geschossmodell, eine für den Geschoss-Spawnpunkt und eine für die Bullet-Geschwindigkeit und und ich weiß nicht, wie ich das beheben kann. Könnte mir jemand helfen? Ich bin neu im Codieren und verwende Visual Studio mit Unity. Ich habe ein YouTube-Tutorial befolgt. Das ist mein Code:
[code]using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR.Interaction.Toolkit;
public class FireBulletOnActivate : MonoBehaviour
{
public GameObject bullet;
public Transform spawnPoint;
public float fireSpeed = 20;
// Start is called before the first frame update
void Start()
{
XRGrabInteractable grabbable = GetComponent();
grabbable.activated.AddListener(FireBullet);
}
// Update is called once per frame
void Update()
{
}
public void FireBullet(ActivateEventArgs arg)
{
GameObject spawnedBullet = Instantiate(bullet);
spawnedBullet.transform.position = spawnPoint.position;
spawnedBullet.GetComponent().velocity =
spawnPoint.forward * fireSpeed;
Destroy(spawnedBullet, 5);
}
}
[/code]
Das Video, dem ich gefolgt bin, ist hier---> [youtube]0xt6dACM_1I[/youtube]