Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by schult777 · Mar 08, 2014 at 11:07 PM · tagmultiplelaser

laser is not working

I have a script that I have been working on for a while now. I have it almost done and ready to go. I have it so that it has multiple if statements in it so I can target different items and have it so that different things will happen to each item, or so I hope. It is not working out that way. When I fire the laser it goes toward but not directly at the object tagged Drone. It will not fire in any other direction. I need to know why that is. Please look over my script and tell me what is wrong with it. Thank you. using UnityEngine; using System.Collections;

public class Beamlaser : MonoBehaviour { LineRenderer line; public GameObject other; public GameObject explosion;

 void Start () 
 {
     line = gameObject.GetComponent<LineRenderer>();
     line.enabled = false;
 }
 
 
 void Update () 
 {
     if(Input.GetButtonDown("Fire1"))
         
     {
         StopCoroutine("FireLaser");
         StartCoroutine("FireLaser", .25F);
         audio.Play();
         
     }
 }
 IEnumerator FireLaser(float lengthOfTime)
 {
     line.enabled = true;
     var t = Time.time;
     
     while(Input.GetButton("Fire1") && Time.time - t < lengthOfTime)
         
     {
         Ray ray = new Ray(transform.position, transform.forward);
         RaycastHit hit;
         
         line.SetPosition(0, ray.origin);
         
         if(Physics.Raycast(ray, out hit, 1000))
         {
             line.SetPosition(1, hit.point);
             if(hit.collider.gameObject.tag == "Hand")
             {
             Instantiate(other, hit.point, transform.rotation);
             Destroy(hit.transform.gameObject); 
                             }
         }
         else if(hit.collider.gameObject.tag == "Drone")    
         {
             Instantiate(explosion, hit.point, transform.rotation);
             Destroy(hit.transform.gameObject);
                 line.SetPosition(1, ray.GetPoint(1000));
         
         yield return null;
     }
     line.enabled = false;
     }
 }

}`

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

20 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

Related Questions

How to assign a tag to multiple parts of a Model 0 Answers

Can't get more than one object. 1 Answer

Add script to selection 2 Answers

One script, multiple object texture change 1 Answer

Can I use Multiple tags on if? 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