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
Please keep your answer as simple as possible I am a complete moron I do best with youtube videos Thank You Again