private void UpdateHealth() { barSize = health / 50f; healthBar.SetSize(barSize); if (barSize > 0) { if (barSize < 0.3f) { /*if ((int)(barSize * 100f) % 3 == 0) * { * healtBar.SetColor(Color.white); * } * else * { * healtBar.SetColor(Color.green); * }*/ health30 = true; } else { health30 = false; } } else { Destroy(parent); } }
void Start() { flySpeed = meteorScriptableObject.flySpeed; turnSpeed = meteorScriptableObject.turnSpeed; health = meteorScriptableObject.maxHealth; meteorSize = meteorScriptableObject.meteorSize; meteorDamage = health / 3; parent = transform.parent.gameObject; //rb = transform.Find("Meteor").GetComponent<Rigidbody2D>(); //Wyszukanie komponentu Rigidbody2D z dzieci o nazwie "Meteor" rb = this.GetComponent <Rigidbody2D>(); //Lokalne wyszukanie komponentu Rigidbody rb.gravityScale = 0; rb.angularDrag = 0; healthBar = parent.transform.Find("HealthBar").GetComponent <BarScript>(); float rotationRandom; rotationRandom = Random.Range(-50f, 50f); rb.angularVelocity = turnSpeed * rotationRandom * 10 * Time.fixedDeltaTime; Vector2 randomForce; randomForce = new Vector2(flySpeed * Random.Range(-5f, 5f), flySpeed * Random.Range(-5f, 5f)); Vector2 force; force = randomForce; rb.AddForce(force); healthBar.SetSize(barSize); healthBar.SetColor(Color.green); }