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 /
  • Help Room /
avatar image
0
Question by pre111 · Feb 17, 2018 at 12:55 AM · scriptingproblem

Can Anybody Help Me Please

I have searched for 3 days now and I just do not know how to make this work. I have been working with unity since December and I have learned so much in that short time. But I can see I have a long way to go.

If anyone can point me to the right direction that would be great. I have a scene with exploding barrels right now the explosion is set up with a MouseDown to trigger the explosion.

     using UnityEngine;
     using System.Collections;
     
     public class Barrel_Explode : MonoBehaviour {
         
     public GameObject Barrel;
     public GameObject BarrelExplode;
     public AnimationClip BarrelExplodeAnim;
     public ParticleSystem ExplodeVideoParticles;
     public ParticleSystem ExplodeVideoParticles_Ground;
     public ParticleSystem SmokeParticles;
     public ParticleSystem SparkParticles;
     public Light ExplodeLight;
     public AudioSource ExplodeAudio;
     public GameObject ScorchMark;
     
     private float fadeStart = 15;
     private float fadeEnd = 0;
     private float fadeTime = 1;
     private float t = 0.0f;
     private float pauseTime = 0;
     
     
     void Update (){
        
         if (Input.GetButtonDown("Fire1")) // Detonate on left mouse click
         {
     
             Barrel.SetActive(false);
             BarrelExplode.SetActive(true);
             BarrelExplode.GetComponent<Animation>().Play("BarrelExplodeAnim");
             ExplodeVideoParticles.Play();
             ExplodeVideoParticles_Ground.Play();
             SmokeParticles.Play();
             SparkParticles.Play();
             ExplodeAudio.Play();
             ScorchMark.SetActive(true);
     
             pauseTime = 0;
     
             StartCoroutine("FadeLight");  // Explosion Light
           
          }
     
     
          if (Input.GetButtonDown("Fire2")) // Pause explosion on right mouse click
          {
     
              BarrelExplode.GetComponent<Animation>().Stop("BarrelExplodeAnim");
              SparkParticles.Pause();
              ExplodeVideoParticles.Pause();
              ExplodeVideoParticles_Ground.Pause();
              SmokeParticles.Pause();
              pauseTime = 1;
           
           }
     
     
          if (Input.GetButtonDown("Fire3")) // Reset barrel on middle mouse click
          {
     
              BarrelExplode.GetComponent<Animation>().Stop("BarrelExplodeAnim");
              SparkParticles.Stop();
              ExplodeVideoParticles.Stop();
              ExplodeVideoParticles_Ground.Stop();
              SmokeParticles.Stop();
              Barrel.SetActive(true);
              BarrelExplode.SetActive(false);
              ScorchMark.SetActive(false);
           
           }
     
            
        
     }
     
     
     
     IEnumerator FadeLight (){
        
          while (t < fadeTime) 
          {
     
              if (pauseTime == 0)
              {
                  t += Time.deltaTime;
              }
                    
              ExplodeLight.intensity = Mathf.Lerp(fadeStart, fadeEnd, t / fadeTime);
              yield return 0;
     
          }              
                 
     t = 0;
         
     }
     
     
     }


I am trying to trigger the explosion when I fire my gun I have a bullet script and I am trying to figure out how to make that bullet to the trigger the explosion If anyone can point me in the right direction to making this work that would be very helpful Again I have been trying to figure this out for 3 days and I am getting no were Here is the bullet script

 using UnityEngine;
 using System.Collections;
 
 public class BulletScript : MonoBehaviour {
 
     [Tooltip("Furthest distance bullet will look for target")]
     public float maxDistance = 1000000;
     RaycastHit hit;
     [Tooltip("Prefab of wall damange hit. The object needs 'LevelPart' tag to create decal on it.")]
     public GameObject decalHitWall;
     [Tooltip("Decal will need to be sligtly infront of the wall so it doesnt cause rendeing problems so for best feel put from 0.01-0.1.")]
     public float floatInfrontOfWall;
     [Tooltip("Blood prefab particle this bullet will create upoon hitting enemy")]
     public GameObject bloodEffect;
     [Tooltip("Put Weapon layer and Player layer to ignore bullet raycast.")]
     public LayerMask ignoreLayer;
 
     /*
     * Uppon bullet creation with this script attatched,
     * bullet creates a raycast which searches for corresponding tags.
     * If raycast finds somethig it will create a decal of corresponding tag.
     */
     void Update () {
 
         if(Physics.Raycast(transform.position, transform.forward,out hit, maxDistance, ~ignoreLayer)){
             if(decalHitWall){
                 if(hit.transform.tag == "LevelPart"){
                     Instantiate(decalHitWall, hit.point + hit.normal * floatInfrontOfWall, Quaternion.LookRotation(hit.normal));
                     Destroy(gameObject);
                 }
                 if(hit.transform.tag == "Dummie"){
                     Instantiate(bloodEffect, hit.point, Quaternion.LookRotation(hit.normal));
                     Destroy(gameObject);
                 }
             }        
             Destroy(gameObject);
         }
         Destroy(gameObject, 0.1f);
     }
 
 }
 

Thanks To All Who May Be Able To Help Me Out God Bless

Glen

Comment
Add comment · Show 1
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 pre111 · Feb 17, 2018 at 01:03 AM 0
Share

Please keep your answer as simple as possible I am a complete moron I do best with youtube videos Thank You Again

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

127 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

Related Questions

How to get Unity to stop opening scripts in Visual Studio? 4 Answers

Unity 5 checking if player isGrounded 1 Answer

Issue with player moving forward through collider 0 Answers

RigidBody2D not working right. Help! 0 Answers

How can I check the light intensity??? 0 Answers


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