public void OnCollisionDefault(Collider2D other) { if (other.CompareTag("Obstacle")) { GameObstacle go = other.gameObject.GetComponent <GameObstacle> (); if (go.GetColor() != mr.material.color) { if (onDeath != null) { onDeath(); } } } }
void OnTriggerEnter2D(Collider2D collider) { if (collider.CompareTag("Obstacle")) { GameObstacle go = collider.gameObject.GetComponent <GameObstacle> (); if (go.GetColor() != mr.material.color) { GameObject explPrefab = Resources.Load <GameObject> ("PowerIcons/ExploDeath"); if (onDeath != null) { GameObject g = Instantiate(explPrefab) as GameObject; g.transform.position = transform.position; onDeath(); } } } }
void Update() { if (go == null) { go = GetComponent <GameObstacle> (); } if (go.GetColor() != color) { go.SetColor(color); } if (Time.time - startTime >= waitTime) { startTime = Time.time; waitTime = Random.Range(minTimeBeforeSwitch, maxTimeBeforeSwitch); color = color.r == 0f ? Color.white : Color.black; go.SetColor(color); } }