- Home /
Question by
ericDEV · Jun 09, 2018 at 01:00 PM ·
c#multiplayerproblema
Unity MOBA multiplayer problems with the client to server comunication
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
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Unity multiplayer only localhost 1 Answer
View ID AllocatedID: 150 not found during lookup. Strange behaviour may occur 1 Answer
Application.LoadLevel Strange Problem 2 Answers