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 fancytank · Dec 17, 2013 at 02:16 PM · ontriggerenterif-statements2d-gameplay

OnTriggerEnter or If statement problem

Hello, everyone.
I'm not a native English speaker, so please be generous with my grammatical faults.

Hello,again.
I'm working on 2D game like BubbleBobble(by TAITO), using Unity 4.3 version.
Here's simple rules in my game.

(1) Player blows bubbles, and Enemy meets bubbles, it's captured in bubbles.

(2) Once Enemy is captured in a bubble, it will be destroyed when Player hit it.

So, Enemy has two animations; "Idle" and "Captured", also it has a transition condition Boolean type "IsCaptured", and is set false as default value.

(1) works successfully, but (2) goes strange way, and I don't know why.
Please see my script codes below.


 function OnCollisionEnter(col: Collision) {
         
         myAnim.SetBool("isCaptured",true);
         transform.Translate(Vector2.up * Time.deltaTime);
         this.collider.isTrigger = true;
     }
     
     function OnTriggerEnter(other: Collider)
     {
         if(other.gameObject.tag == "Player" && myAnim.GetBool("isCaptured") == true)
         {
             Destroy(this.gameObject);
         }
     }
 




Problem is, even though the "if statement", all the Enemies are destroyed when they collide with Player!

I can't find where is wrong.
I think it doesn't have any logical errors, but I'm not sure.

Please, help me.(T_T)
I'm so exhausted to find out alone.(T_T)

Comment
Add comment · Show 2
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 Briksins · Dec 17, 2013 at 02:54 PM 0
Share

could you show where you getting from "myAnim" variable? as it is not clear where its co$$anonymous$$g from Are you setting originally ""isCaptured" to false?

avatar image fancytank · Dec 17, 2013 at 04:58 PM 0
Share

"myAnim" variable is in a script attached in Enemy.

var myAnim:Animator;

Also, I set its value is false in a function Start() like...

function Start() {

 myAnim = GetComponent(Animator);
 myAnim.SetBool("isCaptured",false);

}

also did in a Awake(), but the result was same. Enemy's animation works well, so I didn't consider about that.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Melih Şimşek · Dec 17, 2013 at 03:34 PM

I'm not sure what you mean by 'Enemy'. If the Enemy is a Prefab; after destroying Prefabs do not exist inside the scene, they are in the project. You should not be destroying Prefabs, will effect each other.

if you use

 Destroy(this.gameObject);

it'll destroy the gameobject in which you have placed the script....

 Destroy(gameObject);

it'll destroy particular gameobject what you have specified.

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 fancytank · Dec 17, 2013 at 04:48 PM 0
Share

Oh..thank you for the answer. However, I'm afraid to say it's kind of different problem. It seems my explain doesn't have accurate information enough.

First, "Enemy"is a game object, which is prefab. Second, the problem is not "Enemy is destroyed all together at the same time".

The problem is "Enemy must be destroyed only satisfied two conditions; (1) it's in a bubble, (2) it collide with Player." However, When a Player collide with an Enemy, the Enemy is just destroyed. It shouldn't be, because the Enemy is not captured in a bubble.

I checked the state of Enemy's animator is clearly "IsCaptured", and also checked the collide with Player. I can't find why...(T_T)

avatar image
0

Answer by fancytank · Dec 18, 2013 at 07:15 AM

Is there anyone have any idea about this, anymore? T_T

Unity's expert doesn't check these questions? T_T

Comment
Add comment · 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

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

19 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

Related Questions

if statement for 6 ints help C# 2 Answers

Help returning a true varaible 4 Answers

Can't call GetKey inside OnTriggerEnter? 2 Answers

OntriggerEnter condition with two colliders 2 Answers

Get WHICH trigger for OnTriggerEnter? 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