Könnte mir jemand mit diesem Code helfen? Ich versuche, meine Waffe in meinem VR-Spiel zum Schießen zu bringenC#

Ein Treffpunkt für C#-Programmierer
Anonymous
 Könnte mir jemand mit diesem Code helfen? Ich versuche, meine Waffe in meinem VR-Spiel zum Schießen zu bringen

Post by Anonymous »

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--->

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post