-
-
Save xiaoxiao921/2aed4cdac1352a41e087908a51cf27ec to your computer and use it in GitHub Desktop.
UNetWeaver - Class Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using EntityStates.Drone.DroneWeapon; | |
using RoR2; | |
using RoR2.Projectile; | |
using UnityEngine; | |
using UnityEngine.Networking; | |
namespace CustomItem | |
{ | |
internal class NetworkMePlease : NetworkBehaviour | |
{ | |
private const float MaxDistance = 1000f; | |
private const float DamageStat = 20f; | |
public void Update() | |
{ | |
// Make the code only execute if you are a client | |
if (NetworkServer.active) | |
return; | |
if (Input.GetKeyDown(KeyCode.Space)) | |
{ | |
CmdDoFire(); | |
} | |
} | |
// Command attribute means that this code will only be fired by the server | |
[Command] | |
void CmdDoFire() | |
{ | |
var aimRay = new Ray(transform.position, transform.forward); | |
Vector3 forward = aimRay.direction; | |
Vector3 position = aimRay.origin; | |
if (transform) | |
{ | |
position = transform.position; | |
if (Physics.Raycast(aimRay, out var raycastHit, MaxDistance, LayerIndex.world.mask | LayerIndex.entityPrecise.mask)) | |
{ | |
forward = raycastHit.point - transform.position; | |
} | |
} | |
ProjectileManager.instance.FireProjectile(FireTwinRocket.projectilePrefab, position, | |
Util.QuaternionSafeLookRotation(forward), gameObject, DamageStat * FireTwinRocket.damageCoefficient, | |
FireTwinRocket.force, Util.CheckRoll(10f)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment