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