Hi,
I have an issue with a Command Methods.
In this method I just want to Instantiate a bullet and change its color.
But on Clients, the bullet has not the right color and it has some problems with the spawning position.
The [command] method is called from a [client] one.
I tried lots of differents ways to do it and I have no clue.
Should I try [ClientRPC] ?
This is my script :
[Command]
void Cmd_SpawnBullet(string _netID)
{
// Get a player in the scene from a dictionnary (keys are : string "PLAYER " + client netID).
// And get his components
MT_Player player = MT_Network_ConnectionManager.GetPlayer(_netID);
MT_Platformer_Controller ctrl = player.GetComponent<MT_Platformer_Controller>();
MT_WeaponManager wm = ctrl.weapon;
// Return the controllers current weapon.
// (Isn't Monobehaviour)
MT_Weapon w = wm.GetWeapon();
Vector3 rotation = ctrl.muzzle.up;
if (!ctrl.facingRight)
rotation *= 180f;
// Instantiating bullet
GameObject bullet = (GameObject)Instantiate(wm.projectile,
ctrl.muzzle.position,
Quaternion.Euler(rotation)
);
// Changing bullet color
// bullet.GetComponent<SpriteRenderer>().color = Color.red; // Doesn't work
bullet.GetComponent<SpriteRenderer>().color = w.wColor;
// Spawning bullet on Clients
NetworkServer.Spawn(bullet);
}