public void Create(string s) { Debug.Log(s); GameObject newThing = Instantiate(Resources.Load("misc/" + s, typeof(GameObject)) as GameObject) as GameObject; switch (Gameplay.Instance().currentLevel) { case 1: newThing.transform.position = new Vector3(transform.position.x - 2f, transform.position.y - 4f, -2f); tutorialBox = newThing; // newThing.GetComponent<Box>().boxDrop.Play(); break; case 2: newThing.transform.parent = GameObject.Find("FloorTiles").transform; newThing.transform.localScale = new Vector3(3.5f, 3f, 1f); newThing.transform.position = new Vector3(4.25f, 6f, 1f); break; default: newThing.transform.position = new Vector3(-6f, 43f, -1f); break; } if (newThing.transform.Find("Sprite")) { SpriteOrderer.Instance().allSpriteRenderers.Add(newThing.transform.Find("Sprite").gameObject.GetComponent <SpriteRenderer>()); } newThing.name = newThing.name.Replace("(Clone)", ""); }
public void Awake() { south = transform.Find("SouthSpawn").position; north = transform.Find("NorthSpawn").position; east = transform.Find("EastSpawn").position; boxes = new GameObject[boxLimit]; box = Resources.Load("Misc/Box", typeof(GameObject)) as GameObject; for (int i = 0; i < boxLimit; i++) { GameObject b = Instantiate(box as GameObject) as GameObject; b.gameObject.GetComponent <Box>().startScale = b.transform.localScale; boxes[i] = b; b.transform.position = new Vector3(-10000f, 5f * i, 0f); b.transform.parent = transform; b.transform.Find("Sprite").gameObject.GetComponent <Renderer>().enabled = false; b.transform.Find("Collider").gameObject.GetComponent <Collider>().enabled = false; b.name = b.name.Replace("(Clone)", ""); // b.GetComponent<Box>().isDoomed = false; SpriteOrderer.Instance().allSpriteRenderers.Add(b.transform.Find("Sprite").gameObject.GetComponent <SpriteRenderer>()); } boxIndex = 0; id = 0; numberOfSpawners = 3; }
public static SpriteOrderer Instance() { if (instance == null) { instance = GameObject.FindObjectOfType <SpriteOrderer>(); } return(instance); }
public override void OnInspectorGUI() { DrawDefaultInspector(); SpriteOrderer orderer = (SpriteOrderer)target; if (GUILayout.Button("Order Sprites")) { orderer.OrderAll(); } }
public void Respawn() { isDead = false; Vector3 proposedPos = Random.onUnitSphere * 16; while (Vector3.Distance(proposedPos, player.transform.position) < 14) { proposedPos = Random.onUnitSphere * 16; } // Vector2 newPosition = proposedPos; transform.position = new Vector3(proposedPos.x, proposedPos.y, -.5f); spriteRenderer.enabled = true; collider.enabled = true; SpriteOrderer.Instance().allSpriteRenderers.Add(transform.Find("Sprite").gameObject.GetComponent <SpriteRenderer>()); // monsterIndex++;; }
public void Start() { // boxes = new GameObject[itemsToSpawn]; // int limit = boxLimit; itemsPerRow = Mathf.Floor(roomWidth / itemWidth); rowLimit = Mathf.Floor(roomHeight / itemHeight); // numberOfRows = Mathf.Floor(itemsToSpawn/itemsPerRow); Vector3 startPoint = new Vector3(-roomWidth - 5f, -roomHeight - 2f, 0f) / 100; box = Resources.Load("Misc/Box", typeof(GameObject)) as GameObject; for (int i = 0; i < rowLimit; i++) { for (int j = 0; j < itemsPerRow; j++) { // Debug.Log(i + " , " + j); float xOffset = (itemWidth / 10); float yOffset = (itemHeight / 10); GameObject b = Instantiate(box as GameObject) as GameObject; b.name = b.name.Replace("(Clone)", ""); // boxes.Add(b); b.transform.parent = transform; b.transform.localPosition = new Vector3(startPoint.x + (j * .1f), startPoint.y + (i * .12f), 0f); b.transform.Find("Sprite").gameObject.GetComponent <Renderer>().enabled = true; b.transform.Find("Collider").gameObject.GetComponent <Collider>().enabled = true; SpriteOrderer.Instance().allSpriteRenderers.Add(b.transform.Find("Sprite").gameObject.GetComponent <SpriteRenderer>()); } } }
public void Fire() { EnableBeam(); int distance = laserRange; RaycastHit[] hits; Vector3 positionModifier = Vector3.zero; switch (transform.parent.gameObject.GetComponent <Player>().playerDirection) { case (0): positionModifier = -transform.up; break; case (1): positionModifier = -transform.right; break; case (2): positionModifier = transform.up; break; case (3): positionModifier = transform.right; break; default: break; } Vector3 colliderPosition = Player.Instance().transform.Find("Collider").position; Vector3 ray = new Vector3(colliderPosition.x, colliderPosition.y, Player.Instance().transform.position.z); // RaycastHit[] hits = Physics.SphereCastAll(ray, .4f, transform.forward, distance); foreach (RaycastHit h in hits) { // Debug.Log(h.transform.parent.tag); // Debug.DrawRay(ray - positionModifier, transform.forward, Color.green, distance); if (h.transform.tag == "Box") { // Debug.Log("IT'S A BEAM!"); // laserTimer = laserDuration; // beamMesh.enabled = true; // GetComponent<AudioSource>().Play(); // Debug.Log(h.transform.tag); h.transform.Find("Sprite").gameObject.GetComponent <SpriteRenderer>().enabled = false; h.transform.Find("Collider").gameObject.GetComponent <Collider>().enabled = false; } else if (h.transform.tag == "Monster") { Debug.Log("Enemy Hit"); h.transform.gameObject.GetComponent <DepMonsterAI>().Kill(); } else if (h.transform.tag == "VanishingMonster") { h.transform.gameObject.GetComponent <VanishingMonster>().Disappear(); } else if (h.transform.parent == null) { // catch gameobjects without parents before checking their tag to prevent breaking } else if (h.transform.parent.tag == "Breakable") { GameObject g = h.transform.parent.gameObject; // g.transform.Find("Collider").gameObject.GetComponent<Collider>().enabled = false; // g.transform.Find("Model").gameObject.GetComponent<MeshRenderer>().enabled = false; Destroy(g); } else if (h.transform.parent.tag == "Door") { GameObject g = h.transform.parent.gameObject; // SpriteOrderer.Instance().allSpriteRenderers.Remove(h.transform.parent.Find("Model").gameObject.GetComponent<Renderer>()); // SpriteOrderer.Instance().allSpriteRenderers.Remove(h.transform.parent.Find("Model/Wall Crack").gameObject.GetComponent<SpriteRenderer>()); Destroy(g); } else if (h.transform.parent.tag == "Wall") { GameObject g = h.transform.parent.gameObject; SpriteOrderer.Instance().allSpriteRenderers.Remove(h.transform.parent.Find("Model").gameObject.GetComponent <SpriteRenderer>()); SpriteOrderer.Instance().allSpriteRenderers.Remove(h.transform.parent.Find("Model/Wall Crack").gameObject.GetComponent <SpriteRenderer>()); Destroy(g); } else { } } }
public void Disappear() { SpriteOrderer.Instance().allSpriteRenderers.Remove(sprite); Destroy(gameObject); }
private void Trade() { Debug.Log("trading"); Player p = Player.Instance(); if (p.hasLoveLetter && name == "Zafeiri") { p.hasLoveLetter = false; GameObject b = GameObject.Find("Bargaining/Items/LoveLetter"); SpriteOrderer.Instance().allSpriteRenderers.Remove(b.transform.Find("Sprite").GetComponent <SpriteRenderer>()); Destroy(b); p.hasTeddyBear = true; item.GetComponent <BargainingItem>().FollowPlayer(); } else if (p.hasPocketwatch && name == "Chrys") { p.hasPocketwatch = false; GameObject b = GameObject.Find("Bargaining/Items/Pocketwatch"); SpriteOrderer.Instance().allSpriteRenderers.Remove(b.transform.Find("Sprite").GetComponent <SpriteRenderer>()); Destroy(b); p.hasDogCollar = true; item.GetComponent <BargainingItem>().FollowPlayer(); } else if (p.hasTeddyBear && name == "Agdi") { p.hasTeddyBear = false; GameObject b = GameObject.Find("Bargaining/Items/TeddyBear"); SpriteOrderer.Instance().allSpriteRenderers.Remove(b.transform.Find("Sprite").GetComponent <SpriteRenderer>()); Destroy(b); p.hasPocketwatch = true; item.GetComponent <BargainingItem>().FollowPlayer(); } else if (p.hasDogCollar && name == "Thura") { p.hasDogCollar = false; GameObject b = GameObject.Find("Bargaining/Items/DogCollar"); SpriteOrderer.Instance().allSpriteRenderers.Remove(b.transform.Find("Sprite").GetComponent <SpriteRenderer>()); Destroy(b); OpenDoor(); } else if (p.hasLantern && name == "Kleis") { p.hasLantern = false; p.transform.Find("Lantern").gameObject.SetActive(false); RevealKey(); } else { } }