Question by
Snownebula · Sep 03, 2017 at 02:47 PM ·
raycast3dfirespace shooterspaceship
Problem with fireing multiple raycasts at once
I am trying to fire 2 raycasts with this but I cant get it to fire from 2 different positions. Can someone help please. Is it not possible to fire 2 raycasts?
Here is a half broken script it works for only one laser but the other wont fire. I removed the stuff trying to double the laser because I'm just not sure how that works. Here is what I have so far, thanks in advance.
using UnityEngine;
using UnityEngine.Networking;
using System.Collections;
public class Laser : NetworkBehaviour
{
private LineRenderer lr;
public GameObject firePoint1;
[SyncVar]
public float damage = 0.01f;
[SyncVar(hook = "UpdateFireLasers")]
public bool fireLasers = false;
public override void OnStartClient()
{
base.OnStartClient();
UpdateFireLasers(fireLasers);
}
void UpdateFireLasers(bool newValue)
{
lr.enabled = true;
lr.SetPosition(0, firePoint1.transform.position);
RaycastHit hit;
if (Physics.Raycast(firePoint1.transform.position, firePoint1.transform.forward, out hit))
{
if (hit.collider)
{
lr.SetPosition(1, hit.point);
hit.collider.gameObject.BroadcastMessage("ApplyDamage", damage);
}
}
else lr.SetPosition(1, firePoint1.transform.forward * 5000);
}
void Start()
{
lr = GetComponent<LineRenderer>();
}
void Update()
{
if (!isLocalPlayer)
{
return;
}
if (Input.GetMouseButton(0))
{
CmdFireLasers();
}
else lr.enabled = false;
}
[Command]
void CmdFireLasers()
{
fireLasers = !fireLasers;
}
}
Comment
Your answer
Follow this Question
Related Questions
game objects leaving trail of it's self 1 Answer
raycasts variations 0 Answers
Calculate normal vector to the plane that was hit by raycast 1 Answer
RayCast From Centre of Camera 1 Answer
Get Direction From Raycast 0 Answers