IEnumerator DigDelay(Vector2 dir, DiggableTile dt) { bool _okayToDig = true; StopMoving(); if (dt.isDiggable()) { if (!dt.isOpen()) { if (_PlayerStats.getStamina() >= _TunnelCost) { _PlayerStats.IncrementStamina(-_TunnelCost); //play Anim _animator.SetTrigger("doDig"); _animMoveDelay = true; StopMoving(); yield return(new WaitForSeconds(2f)); _animMoveDelay = false; dt.DigTile(); } else { _okayToDig = false; } } if (_okayToDig) { _controlled = false; if (!_InGround) { _animator.SetBool("InGround", true); _InGround = true; } _CurrentTunnelTile = dt; if (dir == Vector2.right) { _horizontalMove = 0.75f; } else if (dir == Vector2.left) { _horizontalMove = -0.75f; } else if (dir == Vector2.down || dir == Vector2.up) { // Debug.Log("DT:" + dt.gameObject + " @" + dt.transform.position.y); // Debug.Log("OUR:" + "king" + " @" + this.transform.position.y); //Calculate distance because of weird anchor points? - keep player in middle of tile float newY = (this.transform.position.y - dt.transform.position.y) / 2; //can Div by 2 to alter if sprite is wrong pos if (dir == Vector2.up) { newY = newY - 2; } this.transform.position = new Vector3(dt.transform.position.x, this.transform.position.y - newY, 0); } } } }
public void OnTriggerExit2D(Collider2D collision) { if (collision.transform.GetComponent <DiggableTile>()) { // Debug.Log("Exited Collision w diggable tile"); //Possible to collided with a New Tile Before Exit is called so need this check if (!_InGround) // only keep track of top soil tiles { if (_CurrentSoilTile == collision.transform.GetComponent <DiggableTile>()) { _CurrentSoilTile = null; } } } else if (collision.transform.parent) { // handle if collider is agro range or base range if (collision.transform.GetComponent <BaseHitBox>()) { if (collision.transform.parent.GetComponent <BuildableObject>()) { //Add to our list of interactable things in range _InRange.Remove(collision.transform.parent.gameObject); //Can we search it? if (collision.transform.parent.GetComponent <Searchable>()) { Searchable s = collision.transform.parent.GetComponent <Searchable>(); { s.setActive(false); // Debug.LogWarning("Players in range"); } } } else if (collision.transform.parent.GetComponent <Rodent>()) { if (_InRange.Contains(collision.transform.parent.gameObject)) { _InRange.Remove(collision.transform.parent.gameObject); } } } } }
private IEnumerator Dig() { if (!digging) { digging = true; RaycastHit[] hits = Physics.RaycastAll(droneTransform.position, droneTransform.forward * distance, distance, LayerMask.NameToLayer(rayTag)); foreach (RaycastHit h in hits) { DiggableTile diggableTile = h.collider.GetComponentInChildren <DiggableTile>(); if (diggableTile != null) { diggableTile.Dig(); } } yield return(new WaitForSeconds(diggingDuration)); digging = false; } }
//Collect Pickups and search and attack things public void OnTriggerEnter2D(Collider2D collision) { //Debug.Log("Enter Trigger with" + collision.transform.gameObject); if (_wantToAttack && _AttackTarget != null) { if (collision.gameObject.transform.parent) { print("ATTACK$44?"); if (collision.gameObject.transform.parent.gameObject == _AttackTarget) { Attack(); } } } else if (_MoveLocation == collision.gameObject) { _horizontalMove = 0; } if (collision.transform.GetComponent <DiggableTile>()) { // Debug.Log("Collider w diggable tile"); if (!_InGround) // only keep track of top soil tiles { _CurrentSoilTile = collision.transform.GetComponent <DiggableTile>(); } } else if (collision.transform.parent) { // handle if collider is agro range or base range if (collision.transform.GetComponent <BaseHitBox>()) { //print("Collided with a base hitbox"); if (collision.transform.parent.GetComponent <BuildableObject>()) { // print("collded with a buildng hitbox"); //Add to our list of interactable things in range _InRange.Add(collision.transform.parent.gameObject); //print("Added: " + collision.transform.parent.gameObject); //Can we search it? if (collision.transform.parent.GetComponent <Searchable>()) { Searchable s = collision.transform.parent.GetComponent <Searchable>(); { s.setActive(true); // Debug.LogWarning("Players in range"); } } } else if (collision.transform.parent.GetComponent <Rodent>()) { //Add to our list of interactable things in range Rodent r = collision.transform.parent.GetComponent <Rodent>(); if (r.getTeam() == 2 && _InRange.Contains(collision.transform.parent.gameObject) == false) { _InRange.Add(collision.transform.parent.gameObject); } } } } ///Old Game Jam code, could be reused for pickups else if (collision.transform.GetComponent <CoinResource>()) { // if (collision.transform.GetComponent<CoinResource>().isActive()) { ResourceManagerScript.Instance.incrementResource(ResourceManagerScript.ResourceType.Trash, 1); Destroy(collision.gameObject); } } }
public bool CheckTile(string Direction) { // Debug.Log("ourPos:" + this.transform.position); Vector3 location; Vector2 directionVector = Vector2.zero; if (_CurrentTunnelTile != null) { location = _CurrentTunnelTile.transform.position; } else { location = _CurrentSoilTile.transform.position; } if (Direction.Equals("right")) { directionVector = Vector2.right; // location += new Vector3(-1f, 0, 0); } else if (Direction.Equals("left")) { directionVector = Vector2.left; //Character is oddly offset due to tail? //location += new Vector3(1, 0, 0); } else if (Direction.Equals("up")) { directionVector = Vector2.up; // location += new Vector3(0.8f, 0, 0); } else if (Direction.Equals("down")) { directionVector = Vector2.down; // location += new Vector3(0.8f, 0, 0); } LayerMask _LayerMask = (1 << 11); // initial hit has to stay right.. or it misses left.. idk wtf its doing RaycastHit2D initialHit = Physics2D.Raycast(location, directionVector, 2f, _LayerMask); RaycastHit2D[] hits = Physics2D.RaycastAll(location, directionVector, 8f, _LayerMask); //Debug stuff Vector2 LocRaised = new Vector2(location.x - 0.1f, location.y + 0.2f); Vector3 pos = (LocRaised + (directionVector * 2)); Debug.DrawLine(LocRaised, pos, Color.blue, 3f); Vector3 pos2 = (new Vector2(location.x, location.y) + (directionVector * 8)); Debug.DrawLine(location, pos2, Color.red, 3f); GameObject localCurrentTile; //Have to be able to find the current tile were on first (Note: _CurrentTile Global is next tile at this point) if (initialHit.collider) { //Debug.Log("Local current tile=" + initialHit.collider.gameObject); localCurrentTile = initialHit.collider.gameObject; foreach (RaycastHit2D h in hits) { if (h.collider.gameObject != localCurrentTile) { if (h.collider.gameObject.GetComponent <DiggableTile>()) { // Debug.Log("Found DiggableTile:" + h.collider.gameObject); DiggableTile dt = h.collider.gameObject.GetComponent <DiggableTile>(); if (dt.isDiggable()) { // Debug.Log("Its True:" + h.collider.gameObject); if ((directionVector == Vector2.right || directionVector == Vector2.left)) { if (!dt.isTopSoil()) { StartCoroutine(DigDelay(directionVector, dt)); _MoveLocation.transform.position = h.collider.gameObject.transform.position; return(true); } } else // up and down { StartCoroutine(DigDelay(directionVector, dt)); return(true); } } } } } } if (directionVector == Vector2.up && _CurrentTunnelTile.isTopSoil() && _CurrentTunnelTile.isDiggable()) { // Debug.Log("IsPassable Top tile:" +_CurrentTopTile); //go up to initial ground level this.transform.position = new Vector3(this.transform.position.x, _YHeight, 0); _MoveLocation.transform.position = new Vector3(this.transform.position.x, _YHeight, 0); _InGround = false; _animator.SetBool("InGround", false); } return(false); }