private void GetEgg() { if (Input.GetButtonDown("Fire1") || Input.GetButtonDown("Fire2") || Input.GetButtonDown("Jump")) { egg = eggDetector.GetEgg(); if (egg) { egg.GetComponent <SphereCollider>().enabled = false; egg.GetComponent <Rigidbody>().useGravity = false; egg.transform.parent = GameObject.Find("HandSlot").transform; } } else if (Input.GetButtonUp("Fire1") || Input.GetButtonUp("Fire2") || Input.GetButtonUp("Jump")) { if (egg) { egg.transform.parent = null; egg.GetComponent <Rigidbody>().useGravity = true; egg.GetComponent <SphereCollider>().enabled = true; } egg = null; } if (egg) { egg.transform.position = GameObject.Find("HandSlot").transform.position; } }
//-------------------------------------------------------- public void OnEggStickToBasket(Egg egg, Basket basket) // Invoke via UnityEvent on Inspector { if (!enable) { return; } t.SetParent(egg.transform); t.localPosition = Vector3.back; t.rotation = Quaternion.identity; Rigidbody2D rb = egg.GetComponent <Rigidbody2D>(); Vector2 throwDirection = basket.GetThrowDirection(rb, strength); int steps = Mathf.CeilToInt(predictDuration_Up / Time.fixedDeltaTime); if (Vector2.Angle(throwDirection, Vector2.up) > 2f) { steps = Mathf.CeilToInt(predictDuration_Other / Time.fixedDeltaTime); } Vector2[] points = Plot(rb, Vector2.zero, throwDirection, steps); lr.positionCount = steps; for (int i = 0; i < steps; ++i) { lr.SetPosition(i, points[i]); } lr.enabled = true; enabled = true; }
//-------------------------------------------------------- void Update() { #if UNITY_EDITOR if (rb.gameObject.activeInHierarchy == false) { Egg e = GameObject.FindObjectOfType <Egg>(); if (e == null) { return; } rb = e.GetComponent <Rigidbody2D>(); if (rb == null) { return; } } #endif if (Input.GetKeyUp(KeyCode.Space) || Input.GetMouseButtonUp(0)) { if (IsStaying()) { Execute(); } } }
public void FixedUpdate() { //Swipe Detection DetectSwipe(); //Accelerometer Detection if (egg.accelEnabled) { Vector3 acc = Input.acceleration; egg.GetComponent <Rigidbody>().AddForce(acc.x * 20f, 0, 0); } //Left if (Input.GetKeyUp(KeyCode.A)) { egg.Left(1); } //Right if (Input.GetKeyUp(KeyCode.D)) { egg.Right(1); } //Up if (Input.GetKeyUp(KeyCode.W)) { egg.Up(1); } }
internal void ResetPlayer() { Debug.Log("Player Reset!"); transform.position = lastCheckpoint.transform.position; rigidbody.velocity = Vector2.zero; egg.transform.position = eggRespawnPosition.position; egg.GetComponent <Rigidbody2D>().velocity = Vector2.zero; }
public void UseSkill() { Egg egg = MonoBehaviour.Instantiate(_eggPrefab).GetComponent <Egg>(); egg.SetEggDamage(_eggDamage); view.PlayEggSound(); egg.transform.position = _eggSpawnPoint.position; egg.GetComponent <Rigidbody2D>().AddForce(new Vector2(_eggSpawnPoint.right.x, 1).normalized *_throwForce, ForceMode2D.Impulse); }
private void EggSpawn() { float eggSize = Random.Range(eggMinSize, eggMaxSize); Egg eggClone = (Egg)Instantiate(eggPrefab, transform.position, transform.rotation); eggClone.transform.SetParent(EggParent.transform); eggClone.transform.localPosition = new Vector3(Random.Range(xMinPos, xMaxPos), EggParent.transform.position.y, 0f); eggClone.transform.localScale = new Vector3(eggSize, eggSize, 0); eggClone.GetComponent <Rigidbody2D>().velocity = new Vector2(0, Random.Range(eggRandomMin, eggRandomMax)); }
override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { ai = animator.GetComponent <Carrier>(); perception = ai.GetComponent <Perception>(); rigidbody = ai.GetComponent <Rigidbody2D>(); movementSpeed = ai.movementSpeed; transform = ai.transform; egg = Instantiate(ai.eggPrefab, new Vector2(transform.position.x, transform.position.y) + ai.eggOffset, Quaternion.identity); egg.transform.parent = transform; eggCollider = egg.GetComponent <Collider2D>(); eggCollider.enabled = false; }
// Update is called once per frame void Update() { timer -= Time.deltaTime; deathTime -= Time.deltaTime; if (timer <= 0) { GetComponent <Animator>().SetInteger("State", 2); this.GetComponent <SpriteRenderer>().enabled = true; GetComponent <Rigidbody2D>().velocity = new Vector2(-0.615f, GetComponent <Rigidbody2D>().velocity.y); } if (deathTime <= 0) { Egg egg = Instantiate <Egg>(eggPrefab, transform.position, transform.rotation); egg.enabled = false; egg.GetComponent <Rigidbody2D>().velocity = new Vector2(-1.1f, egg.GetComponent <Rigidbody2D>().velocity.y); egg.GetComponent <Rigidbody2D>().sharedMaterial = eggMaterial; egg.gameObject.AddComponent <DieAfter>(); egg.gameObject.GetComponent <DieAfter>().time = 4.5f; egg.gameObject.GetComponent <DieAfter>().timer = 4.5f; egg.gameObject.layer = 11; Destroy(this.gameObject); } }
void _ridit() { chickenR = chicken.GetComponent <Rigidbody>(); emuR = emu.GetComponent <Rigidbody>(); wineR = wine.GetComponent <Rigidbody>(); IceCreamR = IceCream.GetComponent <Rigidbody>(); SushiR = Sushi.GetComponent <Rigidbody>(); EggR = Egg.GetComponent <Rigidbody>(); drink1R = drink1.GetComponent <Rigidbody>(); drink2R = drink2.GetComponent <Rigidbody>(); drink3R = drink3.GetComponent <Rigidbody>(); humbugerR = humbuger.GetComponent <Rigidbody>(); ebiR = ebi.GetComponent <Rigidbody>(); tomatoR = tomato.GetComponent <Rigidbody>(); letasR = letas.GetComponent <Rigidbody>(); cosmonautR = cosmonaut.GetComponent <Rigidbody>(); }
// Update is called once per frame void Update() { healthText.text = "Health: " + egg.health; if (speedText != null) { speedText.text = "Speed: " + System.Math.Round(egg.GetComponent <Rigidbody>().velocity.magnitude, 0); } if (accelText != null) { accelText.text = "Accelerometer: " + egg.accelEnabled; } if (egg.gameWon) { LevelComplete(); } }
//-------------------------------------------------------- public void OnEggFallOut(Egg egg) // configured via Inspector // Update lives (internally) { --lives; // Make egg stop interactions egg.GetComponent <Rigidbody2D>().simulated = false; eggThrower.enabled = false; if (lives >= 0) // Continue playing { this.egg = egg; StartCoroutine(Rebirth()); } else // Game over { InvalidateLives(); PopupResult pr = GameObject.FindObjectOfType <PopupResult>(); if (pr != null) { pr.Show(ScoreHolder.instance.totalScore); } } }