Hello, im developing a realistic fps with multiplayer using netcode for gameobjects.
Im stuck at trying to get the muzzle flash effect to show for the other player, my particle system is attached to the gun and played with this function:
{
muzzleFlash.Play();
}```
and im activating this function in an animation with an event.
I tried this:
[ServerRpc]
public void CmdStartParticles()
{
RpcStart_shoot_muzzleflash();
shoot_muzzleflash();
}
[ClientRpc]
public void RpcStart_shoot_muzzleflash()
{
shoot_muzzleflash();
}
public void shoot_muzzleflash()
{
muzzleFlash.Play();
}```
but then i cant choose the CmdStartParticles() as an event in the animation
im experienced with unity but not with netcode, so sorry if this is a noob question
Hi @cesar121321432 ,
Did you read this documentation page?
âCreating a method that ends with the ServerRpc suffix within a NetworkBehaviour derived class.â
No, because the second code block is prob completely wrong, that why im asking the question
there is nothing on the docs about particle systems as far as i can see.
using System.Collections;
using System.Collections.Generic;
using TMPro;
using Unity.Mathematics;
using Unity.Netcode;
using UnityEngine;
public class Makarov : NetworkBehaviour
{
public Animator anim;
public AudioSource src;
public AudioClip shoot_clip;
public ParticleSystem muzzleFlash;
public ParticleSystem smoke;
public Transform gun;
public Vector3 gunaimPos;
public quaternion pivot;
public Transform player;
public float AimSpeed = 5;
public Transform shootpoint;
public GameObject hitEffect;
// Start is called before the first frame update
void Start()
{
gunaimPos = new Vector3(0.117f, 0.018f, 0.083f);
gameObject.GetComponent<NetworkObject>().Spawn();
}
// Update is called once per frame
void Update()
{
player.localRotation = Quaternion.Lerp(player.localRotation, pivot, AimSpeed * Time.deltaTime);
gun.localPosition = Vector3.Slerp(transform.localPosition, gunaimPos, AimSpeed * Time.deltaTime);
if (Input.GetMouseButtonDown(0) && IsLocalPlayer)
{
anim.Play("Makarov_Shoot");
}
if (Input.GetMouseButtonDown(1))
{
if (IsOwner)
{
gunaimPos = new Vector3(0.00400000019f, 0.209999993f, 0.166615874f);
// gun.localPosition = new Vector3(0.002f, 0.134f, 0.083f);
}
}
if (Input.GetMouseButtonUp(1))
{
if (IsOwner)
{
gunaimPos = new Vector3(0.117f, 0.018f, 0.083f);
//gun.localPosition = new Vector3(0.117f, 0.018f, 0.083f);
}
}
/*
if (Input.GetKeyDown("q"))
{
pivot = new quaternion(player.localRotation.x, player.localRotation.y, -10, 0);
if (Input.GetKeyUp("q"))
{
pivot = new quaternion(player.localRotation.x, player.localRotation.y, 0, 0);
}
if (Input.GetKeyDown("e"))
{
pivot = new quaternion(player.localRotation.x, player.localRotation.y, 10, 0);
}
if (Input.GetKeyUp("e"))
{
pivot = new quaternion(player.localRotation.x, player.localRotation.y, 0, 0);
}
*/
}
public void raycast_shoot()
{
RaycastHit hit;
if (Physics.Raycast(shootpoint.transform.position, shootpoint.transform.TransformDirection(Vector3.forward), out hit, Mathf.Infinity))
{
Debug.DrawRay(shootpoint.transform.position, shootpoint.transform.TransformDirection(Vector3.forward) * hit.distance, Color.yellow);
Debug.Log("Did Hit");
Instantiate(hitEffect, hit.point, Quaternion.LookRotation(hit.normal));
}
else
{
Debug.DrawRay(shootpoint.transform.position, shootpoint.transform.TransformDirection(Vector3.forward) * 1000, Color.white);
Debug.Log("Did not Hit");
}
// gameObject.GetComponent<NetworkObject>().Spawn();
}
public void shoot_sound()
{
src.PlayOneShot(shoot_clip);
//gameObject.GetComponent<NetworkObject>().Spawn();
}
public void shoot_Smoke()
{
smoke.Play();
// smoke.gameObject.GetComponent<NetworkObject>().Spawn();
}
[ServerRpc]
public void CmdStartParticlesServerRpc()
{
RpcStart_shoot_muzzleflashClientRpc();
shoot_muzzleflash();
}
[ClientRpc]
public void RpcStart_shoot_muzzleflashClientRpc()
{
shoot_muzzleflash();
}
public void shoot_muzzleflash()
{
muzzleFlash.Play();
}
}