Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Codelyy · May 16, 2016 at 08:07 PM · c#linerendererstatelaser beam

Line Renderer works only once

I'm using a Line renderer to create a channelled Laser beam going from sort of under the enemy firing the laser beam to the top of the screen. It looks like this: alt text

It works fine as you can see but if I want it to fire the laser again in the same session, it will play the animation but the laser won't appear and I'm not sure why.

This is the script I used to create the laser:

 void LaserBeam()
     {
         anim.SetBool("Aggro", true);
         anim.SetTrigger(laserBeamHash);
 
         if(!anim.GetCurrentAnimatorStateInfo(0).IsName("LaserBeam"))
         {
             transform.position = new Vector3(transform.position.x + 0.1f * Time.deltaTime, transform.position.y, transform.position.z);
             return;
         }
 
         transform.position = new Vector3(transform.position.x - 0.3f * Time.deltaTime, transform.position.y, transform.position.z);
         laserBeaming = true;
         RaycastHit2D hit = Physics2D.Linecast(firePoint.transform.position, laserBeamPoint.transform.position, laserBeamLayerMask);
         lineRenderer.enabled = true;
         lineRenderer.sortingOrder = 2;
         lineRenderer.SetPosition(0, firePoint.transform.position);
         lineRenderer.SetPosition(1, laserBeamPoint.transform.position);
         canMove = false;
 
         if(!audioSource.isPlaying)
         {
             audioSource.clip = laserBeamSound;
             audioSource.Play();
         }
 
         if(laserBeamPoint.transform.position.x >= laserBeamPoint2.transform.position.x)
         {
             laserBeamPoint.transform.position = new Vector2(laserBeamPoint.transform.position.x - 0.4f, laserBeamPoint.transform.position.y);
         }
 
         if(laserBeamPoint.transform.position.x <= laserBeamPoint2.transform.position.x)
         {
             laserBeamPoint.transform.position = new Vector2(laserBeamPoint.transform.position.x, laserBeamPoint.transform.position.y + 0.4f);
         } 
 
         if(laserBeamPoint.transform.position.y >= laserBeamPoint3.transform.position.y)
         {
             //lineRenderer.enabled = false;
             audioSource.Stop();
             canMove = true;
             laserBeaming = false;
             lineRenderer.SetPosition(0, Vector3.zero);
             lineRenderer.SetPosition(1, Vector3.zero);
 
             //anim.SetBool("Aggro", false);
         }
 
         if(hit)
         {
             HealthManager.DecreaseHealth("Player", 30);
         }
     }

And how the function is called:

 case EyeBallStates.LaserBeam:
                 int positionSelecter = 0;//Random.Range(0, 2);
                 if(positionSelecter == 0)
                 {
                     transform.position = Vector3.MoveTowards(transform.position, movePoint1.transform.position, moveSpeed * Time.deltaTime);
                     if(transform.position.x >= movePoint1.transform.position.x)
                     {
                         transform.localScale = new Vector3(1, 1, 1);
                         LaserBeam();
                     }
                 }
                 else if(positionSelecter == 1)
                 {
                     transform.position = Vector3.MoveTowards(transform.position, movePoint2.transform.position, moveSpeed * Time.deltaTime);
                     if(transform.position.x <= movePoint2.transform.position.x)
                     {
                         transform.localScale = new Vector3(-1, 1, 1);
                         LaserBeam();
                     }
                 }
 
             break;

Does anyone know what the problem is?

stupid-images-2.jpg (17.2 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

142 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

How to find the radius area of linerencderer drawn circle and move objects inside ? 1 Answer

Serialize a LineRenderer 2 Answers

Drawing line from plane edge 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges