- Home /
Question by
Hero1990 · Feb 07, 2018 at 06:53 PM ·
buttonmultiplayermultiplayer-networkingmultiplayer-tutorial
,UI Button in multiplayer Networking Game is not working......
,I am going to make a multiplayer shooting game. In the game, i have used a UI button to run the player. When I pressed and hold the Button run animation will play and when release animation will stop by using Event-Trigger. In the animator controller i have used a Run bool. When i run the game more than one window after build. The UI Button works only for one machine but for the other machine UI Button does not work.
If anyone have any good idea please share with me i will be very beneficial .
thanks in advance ...!!
I have used this Script... public GameObject bulletPrefab; public Transform bulletSpawn; public AudioSource gunAudio; public Animator anim; public bool run;
// Use this for initialization
void Start ()
{
gunAudio = GetComponent<AudioSource> ();
anim = GetComponent<Animator> ();
run = false;
}
// Update is called once per frame
void Update ()
{
if (!isLocalPlayer)
{
return;
}
float x = Input.GetAxis ("Horizontal") * Time.deltaTime * 150f;
float z = Input.GetAxis ("Vertical") * Time.deltaTime * 3.0f;
transform.Rotate (0, x, 0);
transform.Translate (0, 0, z);
if (run == true)
{
anim.SetBool ("Run", true);
transform.Translate (0, 0, .1f);
}
else
{
anim.SetBool ("Run", false);
}
// For Fire
if (Input.GetKeyDown (KeyCode.Space))
{
CmdFire ();
gunAudio.Play ();
anim.Play ("Shoot", -1, 0f);
}
}
[Command]
void CmdFire()
{
GameObject bullet = (GameObject)Instantiate(bulletPrefab, bulletSpawn.position, bulletSpawn.rotation);
bullet.GetComponent<Rigidbody>().velocity = bullet.transform.forward * 6.0f;
NetworkServer.Spawn(bullet);
Destroy(bullet, 2);
}
public override void OnStartLocalPlayer()
{
GetComponent<SkinnedMeshRenderer> ().material.color = Color.blue;
}
public void OnPress()
{
run = true;
}
public void OnRelease()
{
run = false;
}
}
Comment