Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using Unity.Netcode;
- using Unity.Services.Lobbies;
- using UnityEngine;
- public class Projectile : NetworkBehaviour
- {
- //The speed of the projectile
- public float projectileSpeed = 150;
- //The size the projectile should be
- public float scale = 0.35f;
- //The game object for the projectile that spawns.
- public GameObject projectile;
- // Destroys the bullet if it runs into a wall or something that isint a player.
- void OnTriggerEnter(Collider collider)
- {
- if(IsServer)
- {
- if (collider.gameObject.tag == "Untagged")
- {
- Destroy(projectile);
- }
- }
- }
- public override void OnNetworkSpawn()
- {
- base.OnNetworkSpawn();
- //Sets the projectiles speed on network spawn.
- GetComponent<Rigidbody>().velocity = this.transform.forward * projectileSpeed;
- //Sets the scale of the projectile to the projectile scale.
- projectile.gameObject.transform.localScale = new Vector3(scale, scale, scale);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement