Hi Guys,
I have a line renderer shooting a lazer beam, but it only shoots up down and right. It does not shoot left.
I think I know why. When my object is spun around, like so
if (Input.GetKeyDown("left"))
{
if(move != Player_Move.left)
{
JumpControl();
move = Player_Move.left;
Quaternion rotation = Quaternion.Euler(new Vector3(0,180,0));
transform.rotation = rotation;
}
}
the LineRenderer is no longer visible. It has an on hit particle effect, which is still visible, and showing it’s shooting to the left okay, but the LineRenderer is not showing up. Another this is that doing (0, 0, 180), works, however my avatar is then facing upside down. When I flip him on his horizontal the LineRenderer no longer appears.
The LineRenderer is handled like this:
while (timeElapsed < shotDuration)
{
timeElapsed += Time.deltaTime;
if (lazer != null)
{
instFirePfx.renderer.enabled = true;
lazer.enabled = true;
lazer.renderer.material.mainTextureOffset = new Vector2(0, Time.time);
Ray ray = new Ray(transform.position, transform.right);
RaycastHit2D hit = Physics2D.Raycast(transform.position, transform.right, range, layer);
lazer.SetPosition(0, ray.origin);
if (hit.collider != null)
{
instFirePfx.transform.position = new Vector3(hit.point.x, hit.point.y, (transform.position.z - 2.85f) );
lazer.SetPosition(1, hit.point);
if (hit.collider.gameObject.tag == "Leukemia")
{
GameObject newthingy = Instantiate(firePfx, hit.point, Quaternion.identity) as GameObject;
newthingy.AddComponent<FirePfxScript>();
hit.collider.gameObject.GetComponent<LeukemiaAI>().JustDied();
}
}
else
{
instFirePfx.transform.position = new Vector3(ray.GetPoint(range).x, ray.GetPoint(range).y, (transform.position.z - 2.85f));
lazer.SetPosition(1, ray.GetPoint(range));
}
}
yield return null;
}
Does anyone have any suggestions?
Thanks!