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 /
avatar image
0
Question by vrsponginator · Oct 28, 2014 at 03:27 AM · collisioneventtimed

Initiating several events on collision

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.

Comment
Add comment · Show 3
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 vrsponginator · Oct 28, 2014 at 12:53 AM 1
Share

I have found code samples to invoke an event after a set amount of time. But I need the event to trigger at a very precise time and position, so I$$anonymous$$O it would be better to place a trigger object or instantiate my prefab when the ships coordinates are equal to a set number (since I know these), rather than ti$$anonymous$$g it precisely enough.

I am however, completely lost on how to do this. This is my first time scripting, and the samples I find lead me down a dead end since I don't know enough to fill out the blanks and adapt it to my project.

So for now I am reading basic scripting tutorials to try and gain a little knowledge. But if anyone knows hows to trigger the creation of a prefab at a specific position inside a gameObject from a collision or set of coordinates, that would be just what I need.

avatar image Habitablaba · Oct 28, 2014 at 12:59 AM 0
Share

Please update this question to reflect that you want this based on location, not on time, as that is a bit misleading.
Once the question has been updated, I'll be more than happy to push it through. (Although I'd still like to see some code and some more detail about your question).

$$anonymous$$udos for reading tutorials and learning basic scripting in the mean time, btw :)

avatar image vrsponginator · Oct 28, 2014 at 02:22 AM 0
Share

I have updated my question. Thank you!

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Itaros · Oct 28, 2014 at 03:34 AM

It is simple:

On the code on the trigger collider:

 public EnableEmission[] trigerable;
 void OnTriggerEnter (Collider other){
 foreach(EnableEmission ee in trigerable){
 ee.MakeActive();
 }
 }

Fill the array in inspector.

In EnableEmission scripts add:

 public void MakeActive(){
 //Event code. Activation or whatever
 }

P.S.UnityAnswers code editor is horrible

Btw, it can be achieved in reversed way using .net events. For more information check this: http://msdn.microsoft.com/en-us/library/awbftdfh.aspx

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 vrsponginator · Oct 28, 2014 at 12:42 PM 0
Share

Thank you Itaros !

(I deleted the answer and posted it here as a comment. I'm reading the page you linked me to now, and i placed the code in the class scope. No errors now. Thanks :) )

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Shuriken OnParticledCollision 2 Answers

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

problem with collision detection 0 Answers

Collision based scoring system 1 Answer

Plane flyby triggering/help 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