private void Awake() { rigid = GetComponent <Rigidbody>(); planet = GameObject.FindGameObjectWithTag("Planet").GetComponent <GravityReceiver>(); rigid.useGravity = false; rigid.constraints = RigidbodyConstraints.FreezeRotation; }
void FixedUpdate() { if (hasExploded) { return; } Collider2D[] cols = Physics2D.OverlapCircleAll(transform.position, gravityRadius); if (shouldExplode) { hasExploded = true; GetComponent <SpriteRenderer>().enabled = false; GetComponent <PolygonCollider2D>().enabled = false; GameManager.pc.health -= GameManager.pc.health; Camera.main.GetComponent <SmoothFollow>().enabled = false; for (int i = 0; i < cols.Length; i++) { if (cols[i].gameObject.tag == "UFO") { continue; } GravityReceiver gr = cols[i].GetComponent <GravityReceiver>(); if (gr != null) { gr.alignUp = false; gr.counteractGravity = false; Vector3 force = (cols[i].transform.position - transform.position).normalized * explosionForce; Rigidbody2D rb = cols[i].GetComponent <Rigidbody2D>(); rb.drag = 0; rb.AddForce(force * rb.mass); } } } else { for (int i = 0; i < cols.Length; i++) { GravityReceiver gr = cols[i].GetComponent <GravityReceiver>(); if (gr != null) { Vector3 force = (transform.position - cols[i].transform.position).normalized * gravityScale; cols[i].GetComponent <Rigidbody2D>().AddForce(force); if (gr.alignUp) { cols[i].transform.up = cols[i].transform.position - transform.position; } gr.force += force; } } } }
void Start() { GameManager.SetPlayer(this); GameManager.LoadHighScore(); GameManager.ui.UpdateUI("GameOver", false); numJumps = maxJumps; rb = GetComponent <Rigidbody2D>(); anim = GetComponent <Animator>(); gr = GetComponent <GravityReceiver>(); armLInitRotation = armL.transform.localRotation; armRInitRotation = armR.transform.localRotation; GunController gunCont = ((GameObject)Instantiate(gunPrefab, handL.transform.position, Quaternion.identity, handL.transform)).GetComponent <GunController>(); gunCont.Initialize(this); gun = gunCont.gameObject; health = maxHealth; kills = 0; scrap = 0; }
public static void RemoveGravityReceiver(GravityReceiver receiver) { receivers.Remove(receiver); }
public static void AddGravityReceiver(GravityReceiver receiver) { receivers.Add(receiver); }