Hey everyone. I’m trying to get a series of cannons on a ship to fire at a set location by the collision with a collider trigger.
I have an explosion prefab and a particle system for the smoke. They need to activate at the same time and destroy shortly thereafter.
I have created a box collider tagged as a trigger. My problem is cross-referencing a variable. I have a script attached to the collider, and a script attached to the particlesystems (I have 3 particlesystems as children under one parent gameobject).
My code so far:
// This code is on the trigger collider
using UnityEngine;
using System.Collections;
public class TriggerEvent : MonoBehaviour
{
public bool Col;
void OnTriggerEnter (Collider other)
{
Debug.Log ("Trigger enabled");
Col = true;
}
}
So I’m trying to define a bool variable (Col) that can carry over to a script on all objects that need to do something once the trigger is hit. This will also be used on an object that will instantiate the explosion prefab (for when the cannons fire), as well as playing an animation on the ship itself (swaying from the recoil)
// This code is on each ParticleSystem
using UnityEngine;
using System.Collections;
public class EnableEmission : MonoBehaviour {
// Use this for initialization
void Start () {
GetComponent
}
// Update is called once per frame
void Update () {
if (col == true) {
particleSystem.enableEmission == true;
}
else {
particleSystem.enableEmission == false;
}
}
}
This is my first attempt at scripting so I am sorry if this is really too easy. I have read about GetComponent and GameObject.Find but I am at a loss at how to use them for my project and purpose, I have the same problem with most of the codesamples I find on the net. So until I have expanded my basic knowledge I hope someone can help me with this.
Thank you!
Edit: I thought it was worth noting that this is not a game per say. This is more of an demo. All the player can do is look around. The movement of the ship, when the cannons fire etc is all predefined.