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 Chickenator · Nov 21, 2014 at 07:22 PM · variablebooleanswitchbroadcastmessage

Boolean not switching?

So I have this scipt:

 #pragma strict
  
  private var inArea : boolean = false;
  var missile : Transform;
  var player : GameObject;
  //BlastDistance being called from somewher else
  function BlastDistance () {
  
      inArea = true;
  
  }
  function OnTriggerEnter (meow : Collider) {
  
  if (inArea == true) {
  
      if (meow.gameObject.name == "Player") {
      
      
      Debug.Log ("MEOW");
          }
      }
  }

but the boolean never switches. If you want the script that called it :

 #pragma strict
 
 var partical2 : Transform;
 var blastTrigger : Transform;
 
 function OnCollisionEnter (col : Collision) {
     
     if (col.gameObject.name == "Player") {
     BroadcastMessage ("BlastDistance");
     WaitForSeconds (0.1);
         Destroy (col.gameObject);
     
     }
     
                     Instantiate (partical2, this.transform.position, this.transform.rotation);
                         Destroy (this.gameObject);
 }
     
 Any help?

Thanks in advance.

Comment
Add comment · Show 44
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 MrSoad · Nov 21, 2014 at 07:01 PM 0
Share

For Broadcast$$anonymous$$essage to work the script that it broadcasts to must be on the same object or one of it's children, have you got it setup like this?

avatar image Chickenator · Nov 21, 2014 at 07:09 PM 0
Share

@$$anonymous$$rSoad It's being called by the parent and normally it says that there's no receiver if it doesn't work

avatar image MrSoad · Nov 21, 2014 at 07:16 PM 0
Share

Put some Debug.Log s in your OnCollisionEnter() function, at various points to find out what is and is not getting run at the moment.

avatar image Chickenator · Nov 21, 2014 at 07:40 PM 0
Share

@$$anonymous$$rSoad @Jeff $$anonymous$$esselman I did this script :

 #pragma strict
 
 private var inArea : boolean = false;
 var missile : Transform;
 var player : GameObject;
 
 function BlastDistance () {
 
     inArea = true;
 Debug.Log ("in");
 }
 function OnTriggerEnter (meow : Collider) {
 
 if (inArea == true) {
 Debug.Log ("is true");
     if (meow.gameObject.tag == "Player") {
     
     
     Debug.Log ("Works");
         }
     }
 }
 

and the only one that turned on was "in" Why isn't it turning true?

avatar image MrSoad · Nov 24, 2014 at 05:26 PM 1
Share

I need the objects complete, to see exactly how you have them setup and exactly how their various scripts behave and interact. I don't want to spend time trying to fix something that may be broken of affected be something else. $$anonymous$$eep trying I will have a look when you have given me it whole, thanks.

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by MrSoad · Nov 30, 2014 at 12:53 AM

Hi again, really sorry for not getting back to you sooner! Below are your scripts which are fixed, just replace these in your project. The main issue was that the Player object was being destroyed before the Blast Trigger code was executed, so the Player object was no longer in the blast area. I have moved all the destroy code and particle instantiate into the "stuff" script, now called "Blast_Script". The message triggers and everything works. I have put a quick comment in your "Missile" script about the use of yields, and have reformatted your "controller" code. You might want to rename the "controller" script to something more specific like "Player_Controller_Script", up to you though. Again sorry for the delay, Geometry Wars 3 Dimensions took over my life for a couple of days... :Dlink text


fixed scripts.zip (1.6 kB)
Comment
Add comment · Show 7 · 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 Chickenator · Nov 30, 2014 at 01:47 PM 0
Share

Great thank you :D

avatar image MrSoad · Nov 30, 2014 at 02:33 PM 0
Share

No problem, glad you have it sorted :)

avatar image Chickenator · Nov 30, 2014 at 02:34 PM 1
Share

I would vote it up but I don't have the rep

avatar image MrSoad · Nov 30, 2014 at 02:37 PM 0
Share

Don't worry about that :) You accepted the answer which is a lot more than some people do. Have a +1 for doing what many don't bother to do :D

avatar image Chickenator · Nov 30, 2014 at 02:39 PM 0
Share

Out of interest, is Geometry Wars 3 Dimensions a game you're working on?

Show more comments
avatar image
0

Answer by tw1st3d · Nov 26, 2014 at 05:52 PM

Alright so I haven't worked with the Unity API in quite a while now, but I feel like you could solve this a bit easier with C#. However, I do see that you are working with UnityScript in the question, so feel free to figure it out otherwise if you would rather use that.

However, I think that this simple C# class can do everything you're trying to do, in one file. If there are any syntax issues in the code, I guess I'll leave it up to you to solve them, so you can learn on your own.

Label the file you copy and paste the code into as Blast.cs

 using UnityEngine;
 using System.Collections;
 
 public class Blast : MonoBehavior
 {
     // Store local private boolean
     private bool inArea;
     
     public void Start()
     {
         // At the start, set boolean to false
         this.inArea = false;
     }
     
     public void BlastDistance()
     {
         // On BlastDistance call, set boolean to true
         this.inArea = true;
     }
     
     public void OnTriggerEnter( Collider meow )
     {
         // Log your boolean before you check inArea
         Debug.Log(area.ToString());
         if(inArea) {
             // If meow is a GameObject and it's name == Player
             if (meow is GameObject && meow.gameObject.name == "Player") {
                 Debug.Log("MEOW");
             } else {
                 Debug.Log(meow.GetType().ToString());
                 Debug.Log((meow is GameObject) ? meow.gameObject.name.ToString() : "NOT A GAMEOBJECT");
             }
         }
     }
     
     public IEnumerable OnCollisionEnter( Collider col )
     {
         // Again, check if collider is a gameobject and the name is Player
         if (col is GameObject && col.gameObject.name == "Player") {
             this.BlastDistance();
             yield return new WaitForSeconds (0.1);
             Destroy(col.gameObject);
         } else {
             Debug.Log((col is GameObject) ? col.gameObject.name.toString() : "NOT A GAMEOBJECT");
         }
     }
 }
Comment
Add comment · Show 3 · 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 Chickenator · Nov 26, 2014 at 05:55 PM 0
Share

I don't think I can call BlastDistance() from javascript to c# @tw1st3d

avatar image tw1st3d · Nov 26, 2014 at 06:07 PM 0
Share

Just like I literally said in my post, this one file will do everything you need it to do, on it's own. The OnCollisionEnter() will trigger your BlastDistance(). Read the code, and you might see what's happening.

avatar image Chickenator · Nov 26, 2014 at 06:16 PM 0
Share

@tw1st3d okay sorry I understand but at the moment I'm trying to learn JavaScript and I made this question to learn the problem and the game I'm making is just a test. Thank you for helping and I'm sorry if I wasted your time :)

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Getting Variable value from another object? 1 Answer

Can't assign camera to variable. 2 Answers

Use one variable to reference another variable 1 Answer

Is there a simple replacement for a static variable? 2 Answers

Access a variable from another script in update function 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