void RayCheck(Ray ray) { if (Physics.Raycast(ray, out hit, 10f)) { Debug.DrawRay(transform.position, -transform.up); if (previousRaycastTile == null) { previousRaycastTile = hit.transform.gameObject; currentRaycastTile = hit.transform.gameObject; TileClass _previousRaycastTileClass = previousRaycastTile.GetComponent <TileClass>(); _previousRaycastTileClass.SetColour(playerTileColour); } else { if (hit.transform.gameObject != currentRaycastTile | currentRaycastTile.GetComponent <TileClass>().currentColour != playerTileColour) { previousRaycastTile.GetComponent <TileClass>().SetColour(previousRaycastTile.GetComponent <TileClass>().initialMaterialColour, false, false, true); currentRaycastTile = hit.transform.gameObject; currentRaycastTile.GetComponent <TileClass>().SetColour(playerTileColour); previousRaycastTile = currentRaycastTile; } } } else { if (previousRaycastTile != null) { previousRaycastTile.GetComponent <TileClass>().SetColour(previousRaycastTile.GetComponent <TileClass>().initialMaterialColour); previousRaycastTile = null; } } }
// Start is called before the first frame update void Start() { enemySprite = GetComponentInChildren <SpriteRenderer>(); anim = GetComponent <Animator>(); objectPooler = ObjectPooler.Instance; bfs = BattlefieldScript.Instance; status = GetComponent <EntityStatus>(); ray = new Ray(transform.position, transform.forward); if (Physics.Raycast(ray, out hit, 10f)) { Debug.DrawRay(transform.position, -transform.up); previousRaycastTile = hit.transform.gameObject; previousRaycastTileClass = previousRaycastTile.GetComponent <TileClass>(); previousRaycastTileClass.SetColour(enemyTileColour); currentTile = hit.transform.gameObject; } currentTileClass = currentTile.GetComponent <TileClass>(); currentGridPosition = new Vector2(currentTileClass.gridLocation.x, currentTileClass.gridLocation.y); enemySprite.sortingOrder = -(int)currentTileClass.gridLocation.y + 5; currentTileClass.occupied = true; }
// Update is called once per frame void LateUpdate() { if (isRaycasting == true) { ray = new Ray(transform.position, transform.forward); if (Physics.Raycast(ray, out hit, 10f)) { Debug.DrawRay(transform.position, -transform.up); if (previousRaycastTile == null) { previousRaycastTile = hit.transform.gameObject; currentRaycastTile = previousRaycastTile; previousRaycastTileClass = previousRaycastTile.GetComponent <TileClass>(); previousRaycastTileClass.SetColour(enemyTileColour); } else { if (hit.transform.gameObject != currentRaycastTile || currentRaycastTile.GetComponent <TileClass>().currentColour != enemyTileColour) { previousRaycastTileClass.SetColour(previousRaycastTileClass.initialMaterialColour, false, false, true); currentRaycastTile = hit.transform.gameObject; currentRaycastTile.GetComponent <TileClass>().SetColour(enemyTileColour); previousRaycastTile = currentRaycastTile; previousRaycastTileClass = previousRaycastTile.GetComponent <TileClass>(); } } } else { if (previousRaycastTile != null) { previousRaycastTileClass.SetColour(previousRaycastTileClass.initialMaterialColour); previousRaycastTile = null; } } } }
// Update is called once per frame void LateUpdate() { if (isPaused == false) { rb.velocity = new Vector3(speed, 0, 0); ray = new Ray(transform.position, transform.forward); if (Physics.Raycast(ray, out hit, 10f)) { GameObject _hitTile = hit.transform.gameObject; if (previousTile == null) { previousTile = _hitTile; currentTile = previousTile; currentTileClass = currentTile.GetComponent <TileClass>(); if (_hitTile.GetComponent <TileClass>().occupied != true) { currentTileClass.SetColour(Color.yellow, false, true); } tr.sortingOrder = -(int)currentTileClass.gridLocation.y + 5; } else if (currentTile != _hitTile | currentTileClass.currentColour != Color.yellow) { if (_hitTile.GetComponent <TileClass>().occupied != true) { if (currentTile.GetComponent <TileClass>().occupied != true) { previousTile = currentTile; previousTileClass = previousTile.GetComponent <TileClass>(); previousTileClass.SetColour(previousTileClass.initialMaterialColour); } currentTile = _hitTile; currentTileClass = currentTile.GetComponent <TileClass>(); currentTileClass.SetColour(Color.yellow, false, true, false, 5); tr.sortingOrder = -(int)currentTileClass.gridLocation.y + 5; } } } else { if (previousTile != null) { previousTile = currentTile; previousTileClass = previousTile.GetComponent <TileClass>(); previousTileClass.SetColour(previousTileClass.initialMaterialColour); previousTile = null; previousTileClass = null; currentTile = null; currentTileClass = null; } } } }