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 Styxer · Jan 22, 2014 at 07:34 PM · gameobjectpowerupdifference

differentiate between 3 types of powerups

hi guys i have 3 kinds of powerUps and i want to each of them to do something different for that i used gameObject.Find

but its dosent seems to work(it aint adding points as it should be)

 using UnityEngine;
 using System.Collections;
 
 public class PowerUpScript : MonoBehaviour {
 
 
 //    GameObject powerUp1;
 //    GameObject powerUp2;
 //    GameObject powerUp3;
 
     // Use this for initialization
     void Start () {
         rigidbody.AddTorque( Vector3.forward * 60f );
 //        powerUp1 = GameObject.Find ("powerUp");
 //        powerUp2 = GameObject.Find ("powerUp 2");
 //        powerUp3 = GameObject.Find ("powerUp 3");
 
     }
     void Update()
     {
 
     }
 
     
     void OnTriggerEnter (Collider other) 
     {
 //        
         PadleScript paddleScript = GameObject.Find ("paddle").GetComponent<PadleScript>();
         if (GameObject.Find ("powerUp"))
             paddleScript.AddPoints (100);
         if (GameObject.Find ("powerUp 1"))
             paddleScript.AddPoints (100);
         if (GameObject.Find ("powerUp 2"))
             paddleScript.AddPoints (150);
 
 
 
         Destroy (gameObject);
     }
 }

and here is my other script where the powerups array is initialized:

 using UnityEngine;
 using System.Collections;
 
 public class BrickScript : MonoBehaviour {
     
     static int numBricks = 0;
     public int pointValue = 10;
     public int hitPoints = 1;
     public int powerUpChance = 3;
     
     public GameObject[] powerUpPrefabs;
 
 //    public GameObject BrickMovePrebaf;
     GameObject BrickMove;
 
     
     // Use this for initialization
     void Start () {
         numBricks++;
     }
     
     // Update is called once per frame
     void Update () {
         BrickMove = GameObject.Find ("brickMove");
         if (BrickMove) {
             if (transform.position.x > 7.5f)
                 rigidbody.AddForce(300*Input.GetAxis ("Horizontal"),0,0);
             if (transform.position.x < -7.5f)
                 rigidbody.AddForce(-300*Input.GetAxis ("Horizontal"),0,0);
         }                                   
         
     }
     
     void OnCollisionEnter( Collision col ) {
         hitPoints--;
         
         if ( hitPoints <= 0 ) {
             Die();
         }
     }
     
     void Die() {
         Destroy( gameObject );
         PadleScript paddleScript = GameObject.Find ("paddle").GetComponent<PadleScript>();
         paddleScript.AddPoints (pointValue);
         numBricks--;
 
         if ( Random.Range(0, powerUpChance) == 0 ) 
             Instantiate( powerUpPrefabs[ Random.Range(0, powerUpPrefabs.Length) ] , transform.position, Quaternion.identity );
 
 
         
         if ( numBricks <= 0 ) 
         {
             Application.LoadLevel(Application.loadedLevel + 1);
         }
     }
 }

thanks

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

2 Replies

· Add your reply
  • Sort: 
avatar image
-1

Answer by Styxer · Jan 25, 2014 at 11:53 PM

anyone Else?

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
avatar image
0

Answer by fafase · Jan 22, 2014 at 07:35 PM

See this http://answers.unity3d.com/questions/622942/detecting-a-collision-between-specific-two-objects.html

Comment
Add comment · Show 5 · 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 Styxer · Jan 23, 2014 at 09:58 AM 0
Share

Oky i changed my "if" statemaent to if (col.collider.name == "powerUp") and it didnt worked also i used: Debug.Log (col); to check if my paddle recognize the powerup every time and the log is showing only once

avatar image fafase · Jan 23, 2014 at 10:40 AM 0
Share

In your example the reference is called other, maybe that is your issue. You should paste your code for us to see.

avatar image Styxer · Jan 23, 2014 at 12:40 PM 0
Share

i changed the name from other to col and vice verse and its aint working quit yet

avatar image fafase · Jan 23, 2014 at 12:58 PM 0
Share

you need to show your new code.

avatar image Styxer · Jan 23, 2014 at 01:00 PM 0
Share

Here you go using UnityEngine; using System.Collections;

 public class PowerUpScript : $$anonymous$$onoBehaviour {
 
 
 //    GameObject powerUp1;
 //    GameObject powerUp2;
 //    GameObject powerUp3;
 
     // Use this for initialization
     void Start () {
         rigidbody.AddTorque( Vector3.forward * 60f );
 //        powerUp1 = GameObject.Find ("powerUp");
 //        powerUp2 = GameObject.Find ("powerUp 2");
 //        powerUp3 = GameObject.Find ("powerUp 3");
 
     }
     void Update()
     {
 
     }
 
     
     void OnTriggerEnter (Collider col) 
     {
         Debug.Log (col);
         PadleScript paddleScript = GameObject.Find ("paddle").GetComponent<PadleScript>();
         if (col.collider.name == "powerUp")
             Debug.Log ("1");
         if (col.collider.name == "powerUp 1")
             Debug.Log ("2");
         if (col.collider.name == "powerUp 2")
             Debug.Log ("3");
 
 
 
         Destroy (gameObject);
     }
 }

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

18 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

Related Questions

Difference between gameObject.transform and just transform? 1 Answer

Changing a Player's GameObject when damaged/powerup 0 Answers

using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers

What's the difference between gameObject and transform when using GetComponent 2 Answers

Gameobject Differentiation 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