- Home /
Question by
ericDEV · Jun 09, 2018 at 01:02 PM ·
c#multiplayer-networkingclientproblema
Unity Multiplayer client problem
Hi, I'm having some issues with the UNET client communication with regards to a skill shot system I'm trying to implement, can someone help me? In my case the client just doesn't orientates a empty attached to a indicator (that looks to the mouse position perfectly). Here is the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class SkillShot : NetworkBehaviour {
public string input;
public GameObject indicator;
public GameObject projectile;
public Transform spawn;
PlayerController controller;
public bool canAim = false;
void Start ()
{
controller = GetComponent<PlayerController>();
indicator.SetActive(false);
}
void Update ()
{
if(!isLocalPlayer)
{
return;
}
if(Input.GetButtonDown(input))
{
controller.canMove = false;
indicator.SetActive(true);
canAim = true;
}
if(canAim)
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit))
{
Vector3 hitPoint = hit.point;
Debug.Log(hitPoint);
indicator.transform.LookAt(hitPoint);
if (Input.GetMouseButtonDown(0))
{
CmdShoot();
}
}
}
}
[Command]
void CmdShoot ()
{
GameObject bullet = (GameObject)Instantiate(projectile, spawn.position, spawn.rotation);
bullet.GetComponent<Rigidbody>().velocity = bullet.transform.forward*6;
controller.canMove = true;
canAim = false;
indicator.SetActive(false);
NetworkServer.Spawn(bullet);
Destroy(bullet,2);
}
}
Can someone help?
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612164430im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Illuminating a 3D object's edges OnMouseOver (script in c#)? 1 Answer
Error destroying player over network 1 Answer