Advertisement
Atomic_Violetta

Prefab Script

Mar 23rd, 2024
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.36 KB | Gaming | 0 0
  1.  
  2. using UnityEngine;
  3.  
  4. // This is the Swordbeam script.
  5.  
  6. public class SwordbeamScript : MonoBehaviour
  7. {
  8.  
  9.     // This is my timer.
  10.  
  11.     [SerializeField] private float memberDuration = 1.0f;
  12.     private float memberTimer = 0.0f;
  13.  
  14.     // Start a Swordbeam once when it's created.
  15.     [SerializeField] private GameObject memberSwordbeamPrefab = null;
  16.  
  17.     [SerializeField] private float memberSpeed = 1.0f;
  18.     [SerializeField] private Vector3 memberDirection = Vector3.one;
  19.     // I STILL don't know. Rigid Body.
  20.     private Rigidbody2D memberRigidBody = null;
  21.  
  22.     protected void Start()
  23.     {
  24.         memberTimer = memberDuration;
  25.        
  26.         // Get the rigid body that we added in Unity.
  27.         memberRigidBody = this.GetComponent<Rigidbody2D>();
  28.  
  29.         // Calculate the velocity.
  30.  
  31.         Vector3 localWhichVelocity;
  32.         localWhichVelocity = memberSpeed * memberDirection;
  33.  
  34.     }
  35.  
  36.     // Update a bomb every frame of the game.
  37.  
  38.     protected void Update()
  39.     {
  40.         memberTimer -= Time.deltaTime;
  41.  
  42.         if (memberTimer <= 0.0f)
  43.         {
  44.             this.gameObject.SetActive(false);
  45.         }
  46.  
  47.         Vector3 localPosition;
  48.  
  49.         localPosition = this.transform.position;
  50.  
  51.         Instantiate(memberSwordbeamPrefab, localPosition, Quaternion.identity);
  52.  
  53.  
  54.  
  55.     }
  56.    
  57.  
  58.     // This completes the Swordbeam.
  59.  
  60. }
Tags: Unity
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement