public void Init(BonusDefinition _definition, PlayerController player) { Invoke("Deactivate", UnityEngine.Random.Range(5.0f, 10.0f)); Debug.Log("Init: " + _definition.ToString()); definition = _definition; float posX = player.transform.position.x - UnityEngine.Random.Range(-5.0f, 5.0f); float posY = player.transform.position.y + 10.0f - UnityEngine.Random.Range(-2.0f, 2.0f); this.transform.position = new Vector2(posX, posY); if (this.transform.position.x < player.transform.position.x) { this.GetComponent <Rigidbody2D>().velocity = new Vector2(2.0f, UnityEngine.Random.Range(-0.5f, 0.5f)); } else { this.GetComponent <Rigidbody2D>().velocity = new Vector2(-2.0f, UnityEngine.Random.Range(-0.5f, 0.5f)); } // Change Color SpriteRenderer sr = GetComponentInChildren <SpriteRenderer>(); sr.color = new Color(_definition.Red, _definition.Green, _definition.Blue); }
public void GiveBonus() { GameObject bonus = this.GetComponent <PoolController>().GetBonus(); if (bonus != null) { bonus.SetActive(true); BonusDefinition def = FindObjectOfType <XMLReader>().GetRandomDefinition(); bonus.GetComponent <Bonus>().Init(def, player); } }