Advertisement
Guest User

Untitled

a guest
Aug 17th, 2023
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using Unity.Netcode;
  4. using Unity.Services.Lobbies;
  5. using UnityEngine;
  6.  
  7. public class Projectile : NetworkBehaviour
  8. {
  9. //The speed of the projectile
  10. public float projectileSpeed = 150;
  11.  
  12. //The size the projectile should be
  13. public float scale = 0.35f;
  14.  
  15. //The game object for the projectile that spawns.
  16. public GameObject projectile;
  17.  
  18. // Destroys the bullet if it runs into a wall or something that isint a player.
  19. void OnTriggerEnter(Collider collider)
  20. {
  21. if(IsServer)
  22. {
  23. if (collider.gameObject.tag == "Untagged")
  24. {
  25. Destroy(projectile);
  26. }
  27. }
  28. }
  29.  
  30. public override void OnNetworkSpawn()
  31. {
  32.  
  33. base.OnNetworkSpawn();
  34.  
  35. //Sets the projectiles speed on network spawn.
  36. GetComponent<Rigidbody>().velocity = this.transform.forward * projectileSpeed;
  37.  
  38. //Sets the scale of the projectile to the projectile scale.
  39. projectile.gameObject.transform.localScale = new Vector3(scale, scale, scale);
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement