FGTE6003: Final Major Project - Timeleap Help

BulletCasing.cs

Description

The script handling the bullet casing to be spawned once the weapon is fired.

Script

using UnityEngine; namespace Weapons { [RequireComponent(typeof(Rigidbody))] public class BulletCasing : MonoBehaviour { private Rigidbody _rigidbody; private void Start() { Invoke(nameof(Despawn), 2f); if (TryGetComponent(out _rigidbody)) _rigidbody.velocity = transform.TransformDirection(Vector3.right * 5f); } private void Despawn() { Destroy(gameObject); } } }

Private Methods

Despawn()

Destroys the game object.

Start()

Invokes the despawn function, and tries to get the rigidbody component. Sets the velocity of the pistol spawn casing to the right hand side of the weapon with a multiplier.

Variables

_rigidbody

The rigidbody component attached to the bullet casing.

Last modified: 30 April 2024