Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

LineRenderer only works facing one way

Discussion in 'Scripting' started by Nigey, Oct 27, 2014.

  1. Nigey

    Nigey

    Joined:
    Sep 29, 2013
    Posts:
    1,129
    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

    Code (CSharp):
    1.         if (Input.GetKeyDown("left"))
    2.         {
    3.             if(move != Player_Move.left)
    4.             {
    5.                 JumpControl();
    6.                 move = Player_Move.left;
    7.  
    8.                 Quaternion rotation = Quaternion.Euler(new Vector3(0,180,0));
    9.                 transform.rotation = rotation;
    10.             }
    11.         }
    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:

    Code (CSharp):
    1.            while (timeElapsed < shotDuration)
    2.             {
    3.                 timeElapsed += Time.deltaTime;
    4.  
    5.                 if (lazer != null)
    6.                 {
    7.                     instFirePfx.renderer.enabled = true;
    8.                     lazer.enabled = true;
    9.                     lazer.renderer.material.mainTextureOffset = new Vector2(0, Time.time);
    10.  
    11.                     Ray ray = new Ray(transform.position, transform.right);
    12.                     RaycastHit2D hit = Physics2D.Raycast(transform.position, transform.right, range, layer);
    13.  
    14.                     lazer.SetPosition(0, ray.origin);
    15.  
    16.                     if (hit.collider != null)
    17.                     {
    18.                         instFirePfx.transform.position = new Vector3(hit.point.x, hit.point.y, (transform.position.z - 2.85f) );
    19.                         lazer.SetPosition(1, hit.point);
    20.  
    21.                         if (hit.collider.gameObject.tag == "Leukemia")
    22.                         {
    23.                             GameObject newthingy = Instantiate(firePfx, hit.point, Quaternion.identity) as GameObject;
    24.                             newthingy.AddComponent<FirePfxScript>();
    25.                             hit.collider.gameObject.GetComponent<LeukemiaAI>().JustDied();
    26.                         }
    27.                     }
    28.                     else
    29.                     {
    30.                         instFirePfx.transform.position = new Vector3(ray.GetPoint(range).x, ray.GetPoint(range).y, (transform.position.z - 2.85f));
    31.                         lazer.SetPosition(1, ray.GetPoint(range));
    32.                     }
    33.                 }
    34.  
    35.                 yield return null;
    36.             }
    Does anyone have any suggestions?

    Thanks!
     
  2. Nigey

    Nigey

    Joined:
    Sep 29, 2013
    Posts:
    1,129
    Shameless bump lol
     
  3. Nigey

    Nigey

    Joined:
    Sep 29, 2013
    Posts:
    1,129
    Final shameless bump..?