Skip to content

Instantly share code, notes, and snippets.

@xiaoxiao921
Created March 6, 2020 00:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xiaoxiao921/2aed4cdac1352a41e087908a51cf27ec to your computer and use it in GitHub Desktop.
Save xiaoxiao921/2aed4cdac1352a41e087908a51cf27ec to your computer and use it in GitHub Desktop.
UNetWeaver - Class Example
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