using UnityEngine;
using Mirror;
using System.Collections;
public class LaserGun : NetworkBehaviour
{
public Transform laserTransform;
public LineRenderer line;
// Update is called once per frame
void Update()
{
if(isLocalPlayer && Input.GetKeyDown(KeyCode.Q)){
CmdShoot();
}
}
[Command]
public void CmdShoot(){
Ray ray = new Ray(laserTransform.position, laserTransform.forward);
if(Physics.Raycast(ray, out RaycastHit hit, 100f)){
print(hit.collider.gameObject);
if(hit.collider.gameObject.tag == "Player"){
print("player checked as a player");
StartCoroutine(Respawn(hit.collider.gameObject));
}
print(hit.collider.tag);
RpcDrawLaser(laserTransform.position, hit.point);
}
else{
RpcDrawLaser(laserTransform.position, laserTransform.position + laserTransform.forward * 100f);
}
}
[Server]
IEnumerator Respawn(GameObject go){
print("Player ded");
NetworkServer.UnSpawn(go);
Transform newPos = NetworkManager yield return new WaitForSeconds(0.singleton5f);
NetworkServer.GetStartPositionSpawn(go);
go.transform.position}
= newPos.position; [ClientRpc]
go.transformvoid RpcDrawLaser(Vector3 start, Vector3 end){
StartCoroutine(LaserFlash(start, end));
}
IEnumerator LaserFlash(Vector3 start, Vector3 end){
line.rotationSetPosition(0, =start);
newPos line.rotation;SetPosition(1, end);
yield return new WaitForSeconds(1f0.3f);
NetworkServer line.SpawnSetPosition(go0, Vector3.zero);
line.SetPosition(1, Vector3.zero);
}
}