Jump to content
This site uses cookies! Learn More

This site uses cookies!

armedunity.com uses cookies to improve user experience.

By continuing to use this site, you agree to allow us to store cookies on your computer.

silasfriedrich

Member
  • Content Count

    37
  • Joined

  • Last visited

Everything posted by silasfriedrich

  1. Hi everyone, I have trouble with my spawning system and I can't find a good way to get it to work. So basically in my game you should build a tower with blocks (cubes). And every time you place a new block a new block should spawn at a random spawn. So I worked hours on this and im really bad at scripting. This is what I have : This script is on the blocks: using UnityEngine; using System.Collections; using System.Collections.Generic; public class spawner : MonoBehaviour { public GameObject daspawn2; public bool working = false; public bool ok = false; public bool verloren2 = false; //public BoxCollider boxCol; void Update () { if (!GameObject.Find ("hand2").GetComponent<HandPhysicsController> ().IsHoldingObject2) { ok = true; } else { ok = false; } } void OnTriggerEnter(Collider other){ if(other.tag == "trigger") //if(ok == true) if(verloren2 == false) working = true; daspawn2.SetActive(true); } void OnTriggerExit(Collider other){ if (other.tag == "trigger") if(ok == true) verloren2 = true; } } This is on the base you build on: using UnityEngine; using System.Collections; using System.Collections.Generic; public class gamelogic : MonoBehaviour { private bool ok = false; public bool verloren = false; public Transform[] spawns; public int amountThings = 1; public int i = 0; public Transform[] Bone; void Update () { if (!GameObject.Find ("hand2").GetComponent<HandPhysicsController> ().IsHoldingObject2) { ok = true; } else { ok = false; } } void OnTriggerEnter(Collider other){ if(other.tag == "Block") if(ok == true) if(verloren == false) //activate when readyyyy Spawn(); } public void Spawn() { List<Transform> freeSpawnPoints = new List<Transform>(spawns); List<Transform> freeobjects = new List<Transform>(Bone); for (i = 0; i < amountThings; i++) { if (freeSpawnPoints.Count <=0) return; // Not enough spawn points int index = Random.Range(0, freeSpawnPoints.Count); int randomi = Random.Range(0,freeobjects.Count); Transform pos = freeSpawnPoints[index]; freeSpawnPoints.RemoveAt(index); // remove the spawnpoint from our temporary list freeobjects.RemoveAt(randomi); // remove the object from our temporary list Instantiate(Bone[randomi], pos.position, pos.rotation); } } void OnTriggerExit(Collider other){ if (other.tag == "Block") if(ok == true) verloren = true; } } and this is on a empty gameobject: using UnityEngine; using System.Collections; using System.Collections.Generic; public class spawn : MonoBehaviour { public GameObject daspawn; public bool gut = false; public Transform[] spawns; public int amountThings = 1; public int i = 0; public Transform[] Bone; void Update () { if (GameObject.Find ("Block").GetComponent<spawner> ().working) { gut = true; Spawn2(); } } public void Spawn2() { List<Transform> freeSpawnPoints = new List<Transform>(spawns); List<Transform> freeobjects = new List<Transform>(Bone); for (i = 0; i < amountThings; i++) { if (freeSpawnPoints.Count <=0) return; // Not enough spawn points int index = Random.Range(0, freeSpawnPoints.Count); int randomi = Random.Range(0,freeobjects.Count); Transform pos = freeSpawnPoints[index]; freeSpawnPoints.RemoveAt(index); // remove the spawnpoint from our temporary list freeobjects.RemoveAt(randomi); // remove the object from our temporary list Instantiate(Bone[randomi], pos.position, pos.rotation); daspawn.SetActive(false); } } } Now what working is you place a block on the base. Then a new block spawns at a random location. But if I place the new block on the other it only spawns a new one and then it does not spawn more. Its because I decativated the gameobject holding the spawner script. But I cant find a good way to actiate it again. Does someone have a good idea? Thanks for ever answer Here is a Screenshot of the block and components:
  2. Hi everyone, I have a door that opens and its rotated then, so the problem is there that the boxcollider which defines the area where you can open the door, moves to. So how can I make that this boxcollider does not move when the door moves? Thanks
  3. Works perfect thx
  4. Hi everyone, I have a script for open and close a door and I want to make that the sound close have a delay of 1 second. Does anyone know how i can do this ? this is my function for closing the door: if (Input.GetButtonUp("Fire1") && IsOpen && CanOpen) { StartCoroutine (Closing ()); IsOpen = false; audio.PlayOneShot(close); }
  5. Hi everyone, does someone know or have a script where if you look at a object it gets highlighted (change color, get a border or something). thanks
  6. Hi everyone, I have a script that play randomly audio and now i want a delay after every sound. I tried using waitforseconds function but i cant get it to work. this is the script: var sounds: AudioClip[]; InvokeRepeating("PlayRandom", 0, 1); function PlayRandom(){ if (audio.isPlaying) return; audio.clip = sounds[Random.Range(0,sounds.length)]; audio.Play(); } Thanks
  7. Do you know how I can make that the door can only be open when on a other script public bool locked = flase; is ?
  8. Thanks this one works perfectly.
  9. Hi everyone, I have a problem with making a door. I know how to create a animation for it (I made an empty gameobject and used it as a rotation point). But It never works correctly, I tried so many diffrent scripts an tutorials but it never works. So, does someone know a easy script for open and closing a door? Thanks
  10. Hi everyone, i have a problem with a script that should play sounds in a random order. But I cant hear anything when I test it. This is the script: var sounds: AudioClip[]; function PlayRandom(){ if (audio.isPlaying) return; audio.clip = sounds[Random.Range(0,sounds.length)]; audio.Play(); } I attached the script to a empty gameobject and addet the sounds and a audio source to the object. Does anyone know how to fix this? (my player has a audio listener) thanks
  11. Hi everyone, so I bought candela SSRR yesterday and its awesome. But in front of my camera is a white line. Does anyone have an idea why this line is there ?
  12. yeah, but how can I make that it loads the terrain piece by piece. Because if I have a big terrain like in WOW it would take forever to load.
  13. yeah, but I want a terrain that get procedurally loadet or is it diffrent in WOW ?
  14. I dont want a generated terrain I want to load my terrain like in WOW. So I have a big map and the map gets loadet while playing
  15. you right. So does anybody know how to do this ?
  16. Hey, does anyone have an idea how to create a infinite terrain for a MMO game? I found this in the asset store but i dont know if that is the right thing for a MMO.
  17. I tried this and I really cant get it to work This is the code I came out with: if (showGameOver) { // Define the screen space for the game over window Rect currentGameOver = new Rect(Screen.width/2 - (losePromptWH.x/2), Screen.height/2 - (losePromptWH.y/2), losePromptWH.x, losePromptWH.y); // Generate a box based on the game over window rectangle GUI.Box (currentGameOver, "Game Over", skin.GetStyle("Game Over")); // Draw our current score within the game over window GUI.Label(new Rect(currentGameOver.x + 15f, currentGameOver.y + 250f, Screen.width-20, Screen.height-20), "Score: " + curScore.ToString()); // Draw our highscore within the game over window (if the highscore was beaten, it will show your current score) GUI.Label(new Rect(currentGameOver.x + 150f, currentGameOver.y + 350f, Screen.width-20, Screen.height-20), "High score: " + highscore.ToString()); // Draw a replay button on screen and check to see if it was clicked if (GUI.Button (new Rect(currentGameOver.x + (currentGameOver.width - 110), currentGameOver.y + (currentGameOver.height + 250), 330, 160), "", skin.GetStyle("Play"))) { // If it is clicked, reload the level Application.LoadLevel("5 Level"); // Load the highscore from our save file highscore = PlayerPrefs.GetInt("Highscore"); } if (GUI.Button (new Rect(currentGameOver.x + (currentGameOver.width - 520), currentGameOver.y + (currentGameOver.height + 250), 330, 160), "", skin.GetStyle("back"))) { // If it is clicked, reload the level Application.LoadLevel("1 menu"); } } Does it need this end ? curScore.ToString(), skin.GetStyle("Score")); I tried to do the ending like this but then it doesnt get the style. its just really small and red then.
  18. Hi everyone, My GUI is on my android phone really small and on a other phone much bigger. I know its because of the resolution and I already read many forum post about this problem but none of the solutions workt for me. So I want that the GUI is on every phone the same size. But I really have no idea how to do this. This is my script that creates the GUI: using UnityEngine; using System.Collections; public class GameManager : MonoBehaviour { // The score that the player currently has [HideInInspector] public int curScore; // The highest score the player has reached (saved) private int highscore; // Reference to our custom gui skin public GUISkin skin; // Values defining the width and height of our game over screen public Vector2 losePromptWH; // Boolean to check if we need to end the game or not [HideInInspector] public bool showGameOver; void Start () { // Grab the last saved highscore from the player prefs file highscore = PlayerPrefs.GetInt("Highscore"); } void Update () { // If the bird died and our current score is greater than our saved highscore if (showGameOver && curScore > highscore) { // Set the highscore to our current score highscore = curScore; // Now save the score as our new highscore PlayerPrefs.SetInt("Highscore", highscore); } } void OnGUI() { // Set the GUI's skin to our custom skin GUI.skin = skin; // Show our current score value at the top center of the screen // (note: it uses the custom Score style in our skin) GUI.Label (new Rect(Screen.width/2 - 100,100f,200,200), curScore.ToString(), skin.GetStyle("Score")); // If the bird died, show the game over screen if (showGameOver) { // Define the screen space for the game over window Rect currentGameOver = new Rect(Screen.width/2 - (losePromptWH.x/2), Screen.height/2 - (losePromptWH.y/2), losePromptWH.x, losePromptWH.y); // Generate a box based on the game over window rectangle GUI.Box (currentGameOver, "Game Over", skin.GetStyle("Game Over")); // Draw our current score within the game over window GUI.Label(new Rect(currentGameOver.x + 15f, currentGameOver.y + 250f, currentGameOver.width * .5f, currentGameOver.height * .25f), "Score: " + curScore.ToString()); // Draw our highscore within the game over window (if the highscore was beaten, it will show your current score) GUI.Label(new Rect(currentGameOver.x + 150f, currentGameOver.y + 350f, currentGameOver.width * .5f, currentGameOver.height * .25f), "High score: " + highscore.ToString()); // Draw a replay button on screen and check to see if it was clicked if (GUI.Button (new Rect(currentGameOver.x + (currentGameOver.width - 110), currentGameOver.y + (currentGameOver.height + 250), 330, 160), "", skin.GetStyle("Play"))) { // If it is clicked, reload the level Application.LoadLevel("5 Level"); // Load the highscore from our save file highscore = PlayerPrefs.GetInt("Highscore"); } if (GUI.Button (new Rect(currentGameOver.x + (currentGameOver.width - 520), currentGameOver.y + (currentGameOver.height + 250), 330, 160), "", skin.GetStyle("back"))) { // If it is clicked, reload the level Application.LoadLevel("1 menu"); } } } }
  19. yeah the parent which is the player gets reloaded when the scene get loadet the 2nd time. So does anyone have an idea how to fix this?
  20. now it does not even work on the first time the scene gets loaded.
  21. It still does not work. The problem is that at the first time I switch the scene 1 to scene 2 it works, but if I reload the scene 2 the object is gone. And I want that the object is still there if I reload the scene 2.
  22. Yes and my problem is that if I reload the scene 2 times my object is gone.
  23. Hi everyone, Im sorry if i ask to many questions but im a noob at unity . So I have this script: function Awake () { DontDestroyOnLoad (transform.gameObject); } And its working perfect but now : this script is on a object in the scene 1 now i load scene 2 and its still there but now if I die in the scene 2 and press replay so it loads the scene again the object is gone. How can I fix that? Im thinking about a loop or something will work so i tried this: function Awake () { DontDestroyOnLoad (transform.gameObject); } function Update () { while() { Awake(); yield; } } but i dont know what to write in the condition of the while.
  24. Ohhh lol im stupid . Totaly forget that the If have to be in a function. Thanks
×
×
  • Create New...