private void SpawnMaterial(GameObject corpse) { CameraSFXPlayer.PlayClip("MOW KILL"); int corpseTier = corpse.GetComponent <Corpse>().tier; for (int i = 0; i < nbSpawnMaterial; i++) { var randomOffset = new Vector3(Random.Range(-1f, 1f), Random.Range(-1f, 1f), 0); var randomForce = spawnForce / 2 + spawnForce * Random.value; var spawner = GameObject.Instantiate(Resources.Load("Prefabs/SpawnerTmp"), transform.position - transform.up * 0.5f + randomOffset.normalized * 0.4f, Quaternion.identity) as GameObject; var spawnDir3 = spawner.transform.position - transform.position; var spawnDir = new Vector2(spawnDir3.x, spawnDir3.y); spawner.GetComponent <Rigidbody2D>().AddForce(spawnDir.normalized * randomForce, ForceMode2D.Impulse); spawner.GetComponent <Spawner>().delaySecond = materialSpawnDelay; if (Random.value < neutralMaterialChance) { spawner.GetComponent <Spawner>().item = "MaterialNeutral"; } else { spawner.GetComponent <Spawner>().item = "Material"; //TODO récupérer le bon tier spawner.GetComponent <Spawner>().tier = corpseTier; } } for (int i = 0; i < 3 + corpseTier; i++) { GameObject.Instantiate(Resources.Load <GameObject>("Prefabs/Energy"), transform.position, Quaternion.identity); } Destroy(corpse); }
private void Death() { CameraSFXPlayer.PlayClip("M DEATH"); tag = "Hole"; gameObject.layer = LayerMask.NameToLayer("Hole"); GetComponent <Animator>().SetBool("hasMole", false); GetComponent <Animator>().SetBool("isDead", true); }
public void Pop() { CameraSFXPlayer.PlayClip("M SPAWN"); tag = "Mole"; MaterialTriggered = false; gameObject.layer = LayerMask.NameToLayer("Mole"); GetComponent <Animator>().SetBool("hasMole", true); hp = BaseHp + tier * TierMultiplier; attacTimer = 0; }
// Update is called once per frame void Update() { if (tier == 1) { GetComponent <SpriteRenderer>().color = Color.white; } else if (tier == 2) { GetComponent <SpriteRenderer>().color = Color.yellow; } else if (tier == 3) { GetComponent <SpriteRenderer>().color = Color.red; } attacTimer += Time.deltaTime; if (attacTimer > attacPeriod) { CameraSFXPlayer.PlayClip("M ATTAC"); GetComponent <Animator>().SetBool("isAttac", true); attacTimer -= attacPeriod; } if (stunTimer > 0) { stunTimer -= Time.deltaTime; } else { stunTimer = 0; GetComponent <Animator>().SetBool("isStunned", false); } if (tag == "Mole") { GetComponent <Animator>().SetBool("hasMole", true); } else { GetComponent <Animator>().SetBool("hasMole", false); } if (GetComponent <Animator>().GetCurrentAnimatorStateInfo(0).IsName("Death")) { GetComponent <Animator>().SetBool("isDead", false); } if (GetComponent <Animator>().GetCurrentAnimatorStateInfo(0).IsName("Attac")) { GetComponent <Animator>().SetBool("isAttac", false); } }
private void LoadAmmo(GameObject ammo) { CameraSFXPlayer.PlayClip("SHOOT LOAD"); currentAmmo.Add(ammo.GetComponent <Ammo>().type); Destroy(ammo); if (ammoTimer > 0) { ammoTimer += GetAmmoTimerIncreaseValue(); } }
void OnTriggerEnter2D(Collider2D other) { switch (ControlType) { case PlayerControlType.MOWER: switch (other.gameObject.tag) { case "Mole": MoleBump(other.gameObject); break; case "Drill": DrillStun(other.gameObject); break; case "Corpse": SpawnMaterial(other.gameObject); break; case "Ammo": Destroy(other.gameObject); break; } break; case PlayerControlType.SHOOTER: switch (other.gameObject.tag) { case "Ammo": LoadAmmo(other.gameObject); break; } break; default: break; } if (other.gameObject.tag == "Energy") { if (GM != null) { GM.DoScore(); } //Play PickupSound CameraSFXPlayer.PlayClip("LOOT"); Destroy(other.gameObject); } }
private void MoleBump(GameObject mole) { CameraSFXPlayer.PlayClip("MOW BUMP"); Vector2 offset = mole.GetComponent <Collider2D>().offset; Vector3 normal = (mole.transform.position - transform.position + new Vector3(offset.x, offset.y)).normalized; Vector3 reflected = Vector3.Reflect(transform.up, normal); float angle = Mathf.Atan2(reflected.y, reflected.x) * Mathf.Rad2Deg - 90; transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward); rb.velocity = Vector2.zero; mole.GetComponent <Hole>().Stun(); gameObject.GetComponent <Animator>().SetFloat("mouvementX", transform.up.x); gameObject.GetComponent <Animator>().SetFloat("mouvementY", transform.up.y); }
private void FireDrill() { AimSpriteRenderer.enabled = false; var colliders = HeldDrill.GetComponents <Collider2D>(); foreach (Collider2D col in colliders) { col.enabled = true; } HeldDrill.velocity = this.transform.up * DrillLaunchSpeed; HeldDrill.GetComponent <Drill>().Drilling = true; CameraSFXPlayer.PlayClip("DRILL SHORT"); //TO CHANGE ? GameObject.Destroy(HeldDrill.gameObject, DrillLifeTime); HeldDrill = null; }
private void MatcherUpdate() { if (HeldMaterial != null) { HeldMaterial.position = transform.position; } if (btn1Down) { if (HeldMaterial == null) { Debug.DrawRay(transform.position, latestLookDirection, Color.green, 1); RaycastHit2D hit = Physics2D.Raycast(transform.position, latestLookDirection, MaterialPickupOffset, LayerMask.GetMask("Material")); if (hit) { CameraSFXPlayer.PlayClip("MATCH PICK"); HeldMaterial = hit.collider.transform; var colliders = HeldMaterial.GetComponents <Collider2D>(); foreach (Collider2D col in colliders) { col.enabled = false; } } } else { CameraSFXPlayer.PlayClip("MATCH PICK"); HeldMaterial.position = transform.position + new Vector3(latestLookDirection.x * MaterialPickupOffset, latestLookDirection.y * MaterialPickupOffset); Rigidbody2D otherRb = HeldMaterial.GetComponent <Rigidbody2D>(); if (otherRb != null) { otherRb.velocity = latestLookDirection * currentMovement.magnitude * MatcherThrowSpeed; } var colliders = HeldMaterial.GetComponents <Collider2D>(); foreach (Collider2D col in colliders) { col.enabled = true; } HeldMaterial = null; } } }
private void ShooterUpdate() { if (btn1Held) { if (ammoTimer == 0) { ammoTimer = GetAmmoTimerIncreaseValue(); shootTimer = 0; } if (shootTimer > 0) { CameraSFXPlayer.PlayClip("SHOOT FIRE"); int nbShot = GetNbShot(); float totalAngle = nbShot * 10; for (int i = 0; i < nbShot; i++) { var angleOffset = 5 - totalAngle / 2 + i * 10; var bullet = GameObject.Instantiate(Resources.Load("Prefabs/ProjectileTmp"), transform.position + transform.up * 0.5f, Quaternion.Euler(new Vector3(0, 0, transform.rotation.eulerAngles.z + 90f + angleOffset))) as GameObject; bullet.GetComponent <Bullet>().SetProjectileSpeed(GetShootProjectileSpeed()); bullet.GetComponent <Bullet>().SetNbSplash(GetShootNbSplash()); } shootTimer -= GetShootFireTime(); } shootTimer += Time.deltaTime; } if (ammoTimer > 0) { ammoTimer -= Time.deltaTime; if (ammoTimer <= 0) { currentAmmo.Clear(); ammoTimer = 0; } } }
IEnumerator DetectOthers() { while (true) { if (canFuse) { Collider2D[] results = new Collider2D[20]; AuraCollider.OverlapCollider(new ContactFilter2D() { useTriggers = true, layerMask = LayerMask.GetMask("Material") }, results); MaterialFusion other1 = null; MaterialFusion other2 = null; foreach (Collider2D col in results) { if (col != null) { MaterialFusion mat = col.GetComponent <MaterialFusion>(); if (mat != null && mat.resourceType == this.resourceType && mat.canFuse && mat != this && mat != other1 && mat != other2) { //Match if (other1 == null) { other1 = mat; } else if (other2 == null) { other2 = mat; break; } } } } if (other1 != null && other1.canFuse && other2 != null && other2.canFuse) { CameraSFXPlayer.PlayClip("MATCH"); CameraSFXPlayer.PlayClip("EXPLOSION"); int chainCombo = Mathf.Max(other1.currentChainCombo, other2.currentChainCombo, currentChainCombo); other1.canFuse = false; other2.canFuse = false; this.canFuse = false; // Spawn stuff Vector3 targetPosition = (other1.transform.position + other2.transform.position + transform.position) / 3; GameObject.Destroy(other1.gameObject); GameObject.Destroy(other2.gameObject); GameObject crystal = GameObject.Instantiate(Crystal, targetPosition, Quaternion.identity) as GameObject; crystal.GetComponent <Crystal>().tier = tier; var hits = Physics2D.CircleCastAll(targetPosition, CircleCastRadius, Vector2.up, CircleCastRadius); foreach (RaycastHit2D hit in hits) { if (hit.collider.tag == "Material") { Rigidbody2D otherRb = hit.collider.GetComponent <Rigidbody2D>(); if (otherRb != null) { otherRb.velocity = (otherRb.transform.position - targetPosition).normalized * CircleCastForce; } MaterialFusion otherMat = hit.collider.GetComponent <MaterialFusion>(); if (otherMat != null) { otherMat.currentChainCombo = chainCombo + 1; } } else if (hit.collider.tag == "Mole" && !hit.collider.GetComponent <Hole>().MaterialTriggered) { hit.collider.GetComponent <Hole>().MaterialTriggered = true; //Spawn resource int resourceTier = hit.collider.GetComponent <Hole>().tier; int angle = Random.Range(0, 360); float speed = Random.Range(2f, 3f); GameObject mat = Instantiate(Resources.Load("Prefabs/Material"), hit.collider.transform.position, Quaternion.AngleAxis(angle, Vector3.forward)) as GameObject; mat.GetComponent <Rigidbody2D>().velocity = transform.up * speed; mat.GetComponent <MaterialFusion>().tier = resourceTier; mat.GetComponent <MaterialFusion>().canFuse = true; mat.GetComponent <MaterialFusion>().currentChainCombo = chainCombo + 1; } else if (hit.collider.tag == "Drill") { Destroy(hit.collider.gameObject); } } for (int i = 0; i < 1 + 2 * chainCombo * tier; i++) { GameObject.Instantiate(Resources.Load <GameObject>("Prefabs/Energy"), transform.position, Quaternion.identity); } GameObject.Destroy(this.gameObject); } } yield return(new WaitForSeconds(detectWaitTime)); } }
private void OnTriggerEnter2D(Collider2D collision) { if (GetComponent <Rigidbody2D>().velocity.magnitude > 0 && Drilling) { Vector2 normal = (collision.transform.position - transform.position).normalized; if (collision.tag == "MaterialNeutral") { CameraSFXPlayer.PlayClip("DRILL RBREAK"); Bounce(normal); GameObject.Destroy(collision.gameObject); } if (collision.tag == "Mole") { CameraSFXPlayer.PlayClip("DRILL MBOUNCE"); GameObject.Destroy(this.gameObject); } if (collision.tag == "Corpse") { GameObject.Destroy(collision.gameObject); } if (collision.tag == "GlobalWall") { CameraSFXPlayer.PlayClip("DRILL RBOUNCE"); if (collision.transform.localScale.x > collision.transform.localScale.y) { normal = Vector2.up; } else if (collision.transform.localScale.x < collision.transform.localScale.y) { normal = Vector2.right; } Bounce(normal); } if (collision.tag == "Crystal") { //TODO Damage Crystal var crystal = collision.GetComponent <Crystal>(); bool spawnAmmo = !crystal.TakeDamage(tier * 3); if (spawnAmmo) { CameraSFXPlayer.PlayClip("DRILL CBREAK"); for (int i = 0; i < 1 + 2 * (comboCount + tier); i++) { GameObject.Instantiate(Resources.Load <GameObject>("Prefabs/Energy"), transform.position, Quaternion.identity); } comboCount++; GameObject ammo = GameObject.Instantiate(AmmoPrefab, collision.transform.position, Quaternion.identity); ammo.GetComponent <Ammo>().type = (PlayerControl.AmmoType)crystal.tier; } else { CameraSFXPlayer.PlayClip("DRILL CBOUNCE"); Bounce(normal); } } } }
public void Stun() { CameraSFXPlayer.PlayClip("M STUN"); stunTimer = 20f; GetComponent <Animator>().SetBool("isStunned", true); }
private void DrillStun(GameObject drill) { CameraSFXPlayer.PlayClip("MOW STUN"); StartCoroutine("DrillStunCoroutine"); drill.GetComponent <Rigidbody2D>().AddForce(-transform.up * drillStunForce, ForceMode2D.Impulse); }