void OnTriggerEnter2D(Collider2D other) { Tds_Tile vTile = other.GetComponent <Tds_Tile> (); if (vTile != null) { if (vTile.vTileType == Tds_Tile.cTileType.Destructible) { vTile.TileDie(); } if (vTile.vTileType == Tds_Tile.cTileType.Wall && vRebounce <= 0) { ProjDie(); } else if (vTile.vTileType == Tds_Tile.cTileType.Wall) { CalculateRebounce(other); } } else if (other.tag == "Character") { Tds_Character vChar = other.GetComponent <Tds_Character> (); //make sure the projectile is for the other faction and the target is alive. if (vChar.vFactionType != vProjFactionType && vChar.IsAlive) { vChar.ApplyDamage(vDmg); ProjDie(); } } }
public void ActivateTrap() { if (ElapseTrapTimer >= 0f) { if (TrapIsActivated && CanDoDmg) { //calculate the dist between float vDist = Vector3.Distance(vMainPlayer.transform.position, transform.position); //look around if the player is nearby. Do DMG! if (vMainPlayer != null) { if (vDist <= 1.5f) { vMainPlayer.ApplyDamage(Dmg); CanDoDmg = false; } } } ElapseTrapTimer -= Time.deltaTime; } else { if (!TrapIsActivated) { vCurIndexTile++; //increase animaiton //check if we are at the last one if (vCurIndexTile >= vAnimationList.Count - 1) { TrapIsActivated = true; //get the timer for how log the trap must be kept ON ElapseTrapTimer = ElapseTrapON; } } else { vCurIndexTile--; //decrease animation if (vCurIndexTile <= 0) { TrapIsActivated = false; //get the timer for how log the trap must be kept ON ElapseTrapTimer = ElapseTrapOFF; //re-enable the trap itself to do dmg next time CanDoDmg = true; } } //get the right sprite to show vRenderer.sprite = vAnimationSprite [vCurIndexTile]; } }
// Update is called once per frame void Update() { RaycastHit2D hit = Physics2D.Raycast(transform.position, transform.up); if (hit.transform.tag == "Character") { Tds_Character Char = hit.transform.gameObject.GetComponent <Tds_Character>(); if (Char.IsAlive && timecounter >= 1) { Char.ApplyDamage(1); timecounter = 0; } timecounter += Time.deltaTime; } else { timecounter = 1; } LazerRender.SetPosition(0, transform.position); LazerRender.SetPosition(1, hit.point); }
IEnumerator OnTriggerEnter2D(Collider2D other) { Tds_Tile vTile = other.GetComponent <Tds_Tile>(); if (vTile != null || other.tag == "Ball") { if (vTile != null && vTile.vTileType == Tds_Tile.cTileType.Destructible) { vTile.TileDie(); } if (((vTile != null && vTile.vTileType == Tds_Tile.cTileType.Wall) || other.tag == "Ball") && vRebounce <= 0) { this.vCollider.isTrigger = false; yield return(new WaitForSeconds(0.02f)); ProjDie(); } else if ((vTile != null && vTile.vTileType == Tds_Tile.cTileType.Wall) || other.tag == "Ball") { this.vCollider.isTrigger = false; yield return(new WaitForSeconds(0.02f)); CalculateRebounce(other); } } else if (other.tag == "Character") { Tds_Character vChar = other.GetComponent <Tds_Character>(); //make sure the projectile is for the other faction and the target is alive. if (vChar.vFactionType != vProjFactionType && vChar.IsAlive) { vChar.ApplyDamage(vDmg); ProjDie(); } } }