IEnumerator ReturnEgg() { yield return(new WaitForSeconds(1)); if (!egg) { yield break; } if (egg.items.Count > 0) { StartCoroutine(ReturnEgg()); } else { egg.GetComponent <Animator>().SetTrigger("Close"); anim.SetTrigger("Throw"); yield return(new WaitForSeconds(0.5f)); //wait a sec, throw, then close egg //unfreeze egg Rigidbody2D e = egg.GetComponent <Rigidbody2D>(); e.constraints = RigidbodyConstraints2D.None; e.AddForce(holdingPoint.right * -fireForce * 2); yield return(new WaitForSeconds(0.05f)); for (int i = 0; i < 100; i++) { yield return(new WaitForEndOfFrame()); if (egg) { egg.transform.localScale *= 0.9f; if (egg.transform.localScale.x < 0.1f) { break; } } } if (egg) { Transform part = Instantiate(eggParticle, egg.transform.position, Quaternion.identity).transform; Destroy(egg.gameObject); } //times 5 becuz of hge mass of egg egg = null; } }
public EggData(SaveMaster mast) { int num = mast.capsules.Length; vels = new float[num][]; transes = new float[num][]; allItems = new string[num][]; for (int i = 0; i < mast.capsules.Length; i++) { CapsuleController egg = mast.capsules[i]; Rigidbody2D rb = egg.GetComponent <Rigidbody2D>(); float[] v = new float[2]; v[0] = rb.velocity.x; v[1] = rb.velocity.y; //Debug.Log(v[0] + ' ' + v[1]); vels[i] = v; float[] t = new float[3]; t[0] = egg.transform.position.x; t[1] = egg.transform.position.y; t[2] = egg.transform.rotation.eulerAngles.z; transes[i] = t; allItems[i] = new ItemListSave(egg.stringIts).items.ToArray(); } }
IEnumerator OnBegin() { yield return(new WaitForSeconds(0.5f)); //now check if u have an egg if (!egg) { //check if there is an egg nearby bool obj = Physics2D.OverlapCircle(firePoint.position, 4, eggMask); if (obj) { egg = Physics2D.OverlapCircle(firePoint.position, 1, eggMask).GetComponent <CapsuleController>(); egg.transform.position = firePoint.position; egg.transform.rotation = firePoint.rotation; } else { egg = Instantiate(eggPrefab, firePoint.position, firePoint.rotation); } egg.GetComponent <Rigidbody2D>().constraints = RigidbodyConstraints2D.FreezeAll; egg.transform.parent = transform; } }
void Eggs(AllData allData) { float[][] vels = allData.egg.vels; float[][] transes = allData.egg.transes; string[][] allItems = allData.egg.allItems; for (int i = 0; i < allData.egg.vels.Length; i++) { CapsuleController e = Instantiate(eggPrefab, Vector3.zero, Quaternion.identity); e.transform.position = new Vector3(transes[i][0], transes[i][1], 0); e.transform.rotation = Quaternion.Euler(0, 0, transes[i][2]); Rigidbody2D rb = e.GetComponent <Rigidbody2D>(); rb.velocity = new Vector2(vels[i][0], vels[i][1]); for (int j = 0; j < allItems[i].Length; j++) { Item it = Instantiate(StaticFunctions.GetItemFromString(allItems[i][j]), transform.position, Quaternion.identity); e.AddItem(it); } } }
IEnumerator LaunchEgg() { launching = true; egg.transform.parent = null; Rigidbody2D r = egg.GetComponent <Rigidbody2D>(); r.constraints = RigidbodyConstraints2D.None; egg = null; yield return(new WaitForSeconds(0.25f)); r.AddForce(firePoint.up * launchForce); //r.AddTorque(250); //now make an egg yield return(new WaitForSeconds(0.5f)); egg = Instantiate(eggPrefab, firePoint.position, firePoint.rotation); egg.transform.parent = transform; egg.GetComponent <Rigidbody2D>().constraints = RigidbodyConstraints2D.FreezeAll; launching = false; capacityDisplay.color = Color.red; }
void OnTriggerEnter2D(Collider2D collision) { /* Player hits Enemy */ Enemy enemy = collision.gameObject.GetComponent <Enemy>(); // Dirty hack to prevent sword colliding with other colliders in the same game object if (m_isAttacking && enemy != null && collision.gameObject.tag.Equals("Enemy") && (collision as CapsuleCollider2D) != null) { enemy.TakeDamage(damage); float knockbackDir = this.transform.parent.transform.localScale.x; enemy.GetComponent <Rigidbody2D>().AddForce(new Vector2(knockbackDir * knockbackForce, 400)); } /* Player hits a Button */ Button button = collision.gameObject.GetComponent <Button>(); if (m_isAttacking && button != null) { button.Press(); } /* Enemy hits player */ CapsuleController player = collision.gameObject.GetComponent <CapsuleController>(); if (m_isAttacking && player != null && collision.gameObject.tag.Equals("Player") && (collision as CapsuleCollider2D) != null) { player.TakeDamage(damage); float knockbackDir = this.transform.parent.transform.localScale.x; player.GetComponent <Rigidbody2D>().AddForce(new Vector2(knockbackDir * knockbackForce, 400)); } }
void OnTriggerEnter2D(Collider2D collision) { CapsuleController player = collision.gameObject.GetComponent <CapsuleController>(); if (player != null) { player.TakeDamage(damage); Destroy(gameObject); float knockbackDir = this.transform.localScale.normalized.x * -1; if (force > 0) { player.GetComponent <Rigidbody2D>().AddForce(new Vector2(knockbackDir * force, 400)); } print(force); } else if (collision.gameObject.tag == "Wall") { Destroy(gameObject); } }
private void OnTriggerEnter2D(Collider2D other) { //when hit by a capsule, say this if (other.GetComponent <CapsuleController>()) { egg = other.GetComponent <CapsuleController>(); //THIS IS WHERE THE ITEMS ARE DISSAPEARING WHYYYYYYYYYY //FUTURE SELF FIGURE IT OUT NERDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD //activaate anims anim.SetTrigger("Grab"); //snap egg egg.transform.position = holdingPoint.transform.position; egg.transform.rotation = holdingPoint.transform.rotation; //freeze egg egg.GetComponent <Rigidbody2D>().constraints = RigidbodyConstraints2D.FreezeAll; egg.Unload(gameObject.GetComponent <UnPackager>()); StartCoroutine(ReturnEgg()); } }
private void OnTriggerEnter2D(Collider2D other) { if (other.GetComponent <Item>()) { //so its an item... //okay now load egg with item if (egg) { //now update the sprite display float color = (egg.items.Count * 1f / maxItems * 1f); capacityDisplay.color = new Color((1 - color), color, 0, 1); if (egg.items.Count < maxItems) { //print(other.name); egg.AddItem(other.GetComponent <Item>()); } else { StartCoroutine(LaunchEgg()); } } else { //if no egg, reject other.GetComponent <Rigidbody2D>().AddForce(firePoint.up * -200); //if not launching, that means no egg is being created to replace. So, another must be made if (!launching) { egg = Instantiate(eggPrefab, firePoint.position, firePoint.rotation); egg.transform.parent = transform; egg.GetComponent <Rigidbody2D>().constraints = RigidbodyConstraints2D.FreezeAll; egg.AddItem(other.GetComponent <Item>()); } } } }