private void AnimateMove() { float interpolationValue = 1.0f - (m_actionTimer / m_moveSeconds); Vector3 current = LevelLayout.TilePosToWorldVec3(m_tilePos); Vector3 target = LevelLayout.TilePosToWorldVec3(m_moveTargetPos); transform.position = Vector3.Lerp(current, target, interpolationValue); }
// Use this for initialization protected virtual void Start() { transform.position = LevelLayout.TilePosToWorldVec3(m_tilePos); if (m_facingDirection.magnitude == 1.0f) { transform.rotation = Quaternion.LookRotation(new Vector3(m_facingDirection.x, 0, m_facingDirection.y), Vector3.up); } else if (m_facingDirection.magnitude != 0.0f) { Debug.LogWarning("Entity has a facing direction of " + m_facingDirection + " (magnitude is neither 0 nor 1)."); } if (!m_gameManagerReference) { Debug.LogError("Error: Entity " + this.gameObject + " has an empty GameManager reference!"); } m_gameManagerReference.RegisterEntity(this.gameObject); }
public void Build(LevelLayout inputLayout) { int levelWidth = inputLayout.GetWidth(); int levelHeight = inputLayout.GetHeight(); for (int y = 0; y < levelHeight; ++y) { for (int x = 0; x < levelWidth; ++x) { Vector2Int tilePos = new Vector2Int(x, y); if (inputLayout.IsWalkable(tilePos)) { Vector3 worldPos = LevelLayout.TilePosToWorldVec3(tilePos); GameObject floorMeshClone = (GameObject)Instantiate(m_FloorMesh, worldPos, Quaternion.identity); GameObject ceilingMeshClone = (GameObject)Instantiate(m_CeilingMesh, worldPos, Quaternion.identity); // check neighbours // west if (!inputLayout.IsWalkable(new Vector2Int(tilePos.x - 1, tilePos.y))) { float angle = 90.0f; GameObject wallMeshClone = (GameObject)Instantiate(m_WallMesh, worldPos, Quaternion.AngleAxis(angle, Vector3.up)); GameObject columnMeshClone = (GameObject)Instantiate(m_ColumnMesh, worldPos, Quaternion.AngleAxis(angle, Vector3.up)); } if (!inputLayout.IsWalkable(new Vector2Int(tilePos.x + 1, tilePos.y))) { // east float angle = 270.0f; GameObject wallMeshClone = (GameObject)Instantiate(m_WallMesh, worldPos, Quaternion.AngleAxis(angle, Vector3.up)); GameObject columnMeshClone = (GameObject)Instantiate(m_ColumnMesh, worldPos, Quaternion.AngleAxis(angle, Vector3.up)); } // north if (!inputLayout.IsWalkable(new Vector2Int(tilePos.x, tilePos.y + 1))) { float angle = 180.0f; GameObject wallMeshClone = (GameObject)Instantiate(m_WallMesh, worldPos, Quaternion.AngleAxis(angle, Vector3.up)); GameObject columnMeshClone = (GameObject)Instantiate(m_ColumnMesh, worldPos, Quaternion.AngleAxis(angle, Vector3.up)); } // south if (!inputLayout.IsWalkable(new Vector2Int(tilePos.x, tilePos.y - 1))) { float angle = 0.0f; GameObject wallMeshClone = (GameObject)Instantiate(m_WallMesh, worldPos, Quaternion.AngleAxis(angle, Vector3.up)); GameObject columnMeshClone = (GameObject)Instantiate(m_ColumnMesh, worldPos, Quaternion.AngleAxis(angle, Vector3.up)); } // place prop { float randomValue = Random.value; randomValue *= (m_NumberOfPropVariants - 1); int propIndex = Mathf.RoundToInt(randomValue); randomValue = Random.value; randomValue *= 3; int angle = Mathf.RoundToInt(randomValue); angle *= 90; GameObject propMeshClone = (GameObject)Instantiate(m_PropMeshes[propIndex], worldPos, Quaternion.AngleAxis(angle, Vector3.up)); } } } } }