private float getThreshold(terrain t) { switch (t) { case terrain.WATER: return(0.2f); case terrain.SAND: return(0.23f); case terrain.DIRT: return(0.80f); case terrain.MOUNTAIN: return(0.50f); case terrain.SNOW: return(1.0f); case terrain.GRASS: return(0.65f); case terrain.DESERT: return(0.30f); default: return(0.1f); } }
private GameObject getObject(terrain t) { switch (t) { case terrain.WATER: return(Water); case terrain.SAND: return(Sand); case terrain.DIRT: return(Dirt); case terrain.MOUNTAIN: return(Mountain); case terrain.SNOW: return(Snow); case terrain.GRASS: return(Grass); case terrain.DESERT: return(Desert); case terrain.CAMPSITE: return(Campsite); case terrain.PLOT: return(Plot); default: return(Grass); } }
public bool createGenerator(Floor end) { if(!isEmpty()) return false; has=terrain.generator; GameObject generatorObject = (GameObject)Instantiate( generatorPrefab, new Vector3(transform.position.x, transform.position.y, transform.position.z), Quaternion.identity ); GameObject laserObject = (GameObject)Instantiate( laserPrefab, new Vector3(transform.position.x, transform.position.y, transform.position.z), Quaternion.identity ); laserObject.GetComponent<Laser>().setOriginEnd(generatorObject, end.gameObject); Vector3 vect = end.gameObject.transform.position - generatorObject.transform.position; float ang=Vector3.Angle(new Vector3(0,0,1), vect); if(vect.x<0) ang=ang*(-1); generatorObject.transform.Rotate(new Vector3(0, ang, 0 )); currentObject = generatorObject; generatorObject.tag = "Generator"; emitMineralSprite ("-", GameController.generatorCost.ToString()); emitParticles(1); return true; }
// Use this for initialization void Start() { animalAI = GetComponent <AnimalAI>(); player = GameObject.Find("Player"); terrain t = GameObject.Find("Terrain").GetComponent <terrain>(); range = GameObject.Find("Terrain").GetComponent <terrain>().worldSize; arriveRange = 2; interval = 0; target = Vector3.zero; }
public void LoadValues() { var sprite = GetComponent <SpriteRenderer>().sprite.name; x = int.Parse(Helper.GetXorYFromString(gameObject.name, "-", true)); y = int.Parse(Helper.GetXorYFromString(gameObject.name, "-", false)); var renderer = gameObject.GetComponent <SpriteRenderer>(); // We are assuming if the block has a child, it is a bridge. This is terrible if (sprite.Contains("grass") || sprite.Contains("waste") || this.transform.childCount > 0) { renderer.sortingOrder = 10 + y; terrain = terrain.ground; } else if (sprite.Contains("lava")) { renderer.sortingOrder = 1 + y; gameObject.transform.position += new Vector3(0, -0.18f); terrain = terrain.lava; } else if (sprite.Contains("water")) { renderer.sortingOrder = 1 + y; gameObject.transform.position += new Vector3(0, -0.18f); terrain = terrain.water; } else if (sprite.Contains("snow")) { renderer.sortingOrder = 10 + y; terrain = terrain.snow; } else { Debug.Log("Warning, there is a block with an invalid sprite: " + sprite); } }
//Instantiate a Tower above the Floor public bool createTower(towerType t) { if(!isEmpty()) return false; has=terrain.tower; if (t == towerType.tower1) { GameObject towerObject = (GameObject)Instantiate( tower1Prefab, new Vector3(transform.position.x, transform.position.y, transform.position.z), Quaternion.identity ); currentObject = towerObject; towerObject.tag = "Tower"; emitMineralSprite ("-", GameController.tower1Cost.ToString()); } else if (t == towerType.tower2) { GameObject towerObject = (GameObject)Instantiate( tower2Prefab, new Vector3(transform.position.x, transform.position.y, transform.position.z), Quaternion.identity ); currentObject = towerObject; towerObject.tag = "Tower"; emitMineralSprite ("-", GameController.tower2Cost.ToString()); } else if (t == towerType.tower3) { GameObject towerObject = (GameObject)Instantiate( tower3Prefab, new Vector3(transform.position.x, transform.position.y, transform.position.z), Quaternion.identity ); currentObject = towerObject; towerObject.tag = "Tower"; emitMineralSprite ("-", GameController.tower3Cost.ToString()); } emitParticles(1); return true; }
void OnTriggerEnter2D(Collider2D other) { if (other.tag == "chest") { string powerup = lg.getDrop(); Destroy(other.gameObject); float vol = Random.Range(volLowRange, volHighRange); source.PlayOneShot(powerUpSound, vol); IEnumerator coroutine = setPowerup(powerup); StartCoroutine(coroutine); } else if (other.tag == "sand") { currentTerrain = terrain.sand; } else if (other.tag == "ground") { currentTerrain = terrain.ground; } else if (other.tag == "ice") { currentTerrain = terrain.ice; } }
void Start() { has=terrain.empty; }
//Destroy the currentObject public string deleteObject() { if (isEmpty ()) return ""; string tag = currentObject.tag; if (tag == "Wall") { emitMineralSprite("+", GameController.wallCost.ToString()); } else if (tag == "Tower") { if (currentObject.GetComponent<Tower>().type == towerType.tower1) { emitMineralSprite("+", GameController.tower1Cost.ToString()); tag = "Tower1"; } else if (currentObject.GetComponent<Tower>().type == towerType.tower2) { emitMineralSprite("+", GameController.tower2Cost.ToString()); tag = "Tower2"; } else if (currentObject.GetComponent<Tower>().type == towerType.tower3) { emitMineralSprite("+", GameController.tower3Cost.ToString()); tag = "Tower3"; } } else if (tag == "Generator") { emitMineralSprite("+", GameController.generatorCost.ToString()); } Destroy(currentObject); has=terrain.empty; return tag; }
//Instantiate a Wall above the Floor public bool createWall() { if(!isEmpty()) return false; has=terrain.wall; GameObject wallObject = (GameObject)Instantiate( wallPrefab, new Vector3(transform.position.x, transform.position.y+1.5f, transform.position.z), Quaternion.identity ); currentObject = wallObject; wallObject.tag = "Wall"; emitMineralSprite ("-", GameController.wallCost.ToString()); emitParticles(1); return true; }