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 16, 2014 at 10:06 AM · tagexplosiontargets

how do i use a raycast to hit one target to cause a explosion but hit a second target to cause a different explosion?

I have a script. It is a good script but I want it to cause a explosion on one target but cause a different explosion on the second target. Where can I go get a tutorial on the subject or how do I do it? using UnityEngine; using System.Collections;

 public class basicLaserbeam : MonoBehaviour 
 {
     LineRenderer line;
     public GameObject explosion;
     public AudioClip boom;
 
     void Start () 
     {    
 
         line = gameObject.GetComponent<LineRenderer>();
         line.enabled = false;
     }
     void Update () 
     {
         if(Input.GetButtonDown("Fire1"))
             
         {
             StopCoroutine("FireLaser");
             StartCoroutine("FireLaser", 0.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, 2500))
             {
                 line.SetPosition(1, hit.point);
                 if(hit.rigidbody)
                 {
                     Instantiate(explosion, hit.point, transform.rotation);
                     Destroy(hit.transform.gameObject); 
                     audio.PlayOneShot(boom, 1F);
                                 }
             }
             else 
                 line.SetPosition(1, ray.GetPoint(2500));
             
             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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by jbecana · Mar 16, 2014 at 10:35 AM

You could créate different prefab explosions and instatiate them depending on a target specific info, like tag :

 if  (hit.collider.tag == "Enemy A")
 {
   Instantiate(explosionEnemyA, hit.point, transform.rotation);
 }
 else if  (hit.collider.tag == "Enemy B")
 {
   Instantiate(explosionEnemyB, hit.point, transform.rotation);
 }

Better, you could create arrays for explosionEnemyA, explosionEnemyB, etc.. and pick a random prefab using Mathf.Random.

Comment
Add comment · Show 1 · Share
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
avatar image schult777 · Mar 16, 2014 at 02:41 PM 0
Share

I am going to try this. Thank you for your answer.

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

21 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

Related Questions

blow up bomb when it collides with fire 1 Answer

How to set tag for gameobject created by VectorLine in runtime? 2 Answers

Calling prefabs by name or tag returns null. 1 Answer

Most efficient way to handle projectile collisions? 2 Answers

OnDestroy() object with tag 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