public void SetTeam(int id) { this.id = id; Color c = ColorAlgorithm.GetColor(id); this.SetColor(c); for (int i = 0; i < NUM_OF_BULLETS; i++) { GameObject o = Resources.Load <GameObject>("Bullet"); GameObject o2 = (GameObject)Instantiate(o); //GameObject o2 = PhotonNetwork.Instantiate("Bullet", new Vector3(0, -10, 0), Quaternion.identity, 0); o2.GetComponent <Renderer>().material.color = c; o2.GetComponentInChildren <Light>().color = c; o2.GetComponent <Bullet>().gun = this; o2.layer = 22; //The bullet layer o2.transform.position = new Vector3(0, -1000, 0); if (clip == null) { clip = new Stack <GameObject>(); } clip.Push(o2); } this.gui = GameObject.Find("AmmoCounter"); UpdateUI(); }
public GameObject CreateBullet() { Vector3 rotation = this.gameObject.transform.forward; Vector3 position = this.gameObject.transform.position; GameObject o = Resources.Load <GameObject>("Bullet"); GameObject o2 = (GameObject)Instantiate(o); //GameObject o2 = PhotonNetwork.Instantiate("Bullet", new Vector3(0, -10, 0), Quaternion.identity, 0); Color c = ColorAlgorithm.GetColor(id); o2.GetComponent <Renderer>().material.color = c; o2.GetComponentInChildren <Light>().color = c; o2.GetComponent <Bullet>().gun = this; o2.layer = 22; //The bullet layer o2.transform.position = new Vector3(0, -1000, 0); //o2.transform.position = position + rotation * 0.7f; //bullet.transform.rotation.SetLookRotation(rotation * 3); o2.GetComponent <Rigidbody>().velocity = rotation * BULLET_SPEED; //o2.GetComponent<Bullet>().network = true; //o2.GetComponent<Bullet>().Fire(); return(o2); }
private void Start() { id = (int)_PhotonView.owner.customProperties["ID"]; players[id] = this; _Renderer = this.GetComponentInChildren <Renderer>(); colorIndicator = GameObject.Find("ColorIndicator").GetComponent <Image>(); overviewCamera = GameObject.Find("OverviewCam"); _Camera = GetComponentInChildren <Camera>(); _AudioListener = GetComponentInChildren <AudioListener>(); //Debug.Log("ID: " + id); _Renderer.material.color = ColorAlgorithm.GetColor(id); //Debug.Log(this.gameObject.layer); this.gameObject.layer = LayerMask.NameToLayer("Player " + (id + 1)); //Debug.Log(this.gameObject.layer); teamCamera(_Camera, id); if (_PhotonView.isMine) { overviewCamera.SetActive(false); colorIndicator.color = ColorAlgorithm.GetColor(id); AudioSource audioSource = this.gameObject.AddComponent <AudioSource>(); audioSource.clip = Resources.Load("hillySpace") as AudioClip; audioSource.playOnAwake = true; audioSource.loop = true; audioSource.volume = 0.05f; audioSource.Play(); } GetComponent <UnityStandardAssets.Characters.FirstPerson.FirstPersonController>().enabled = _PhotonView.isMine; _Camera.enabled = _PhotonView.isMine; _AudioListener.enabled = _PhotonView.isMine; GameObject gun1 = Resources.Load <GameObject>("Gun"); GameObject gun2 = (GameObject)Instantiate(gun1); //playerID = player.GetComponent<NetworkPlayer>().id; //playerID = PhotonView.owner.customProperties["ID"] + 1; this.gun = gun2; Vector3 pos1 = this.transform.position; gun2.transform.position = pos1 + this.transform.forward * 2; gun2.transform.parent = this.GetComponentInChildren <Camera>().transform; gun2.GetComponent <Gun>().SetTeam(id); GameController.GenerateLevel(id); }
public static void GenerateLevel(int id)//curent level plane is 50x50 centered on origin { Debug.Log("Generating Level. ID:" + id); playerID = id; color = ColorAlgorithm.GetColor(playerID); /* Puts Walls around Every node */ Object[,,] walls = new Object[10, 10, 2]; //Tot#Walls for nxm grid = n*(m+1)+ m*(n+1) = 2mn+n+m { float x, z; for (int i = 0; i < 10; i++) { x = i * 5 - 25; for (int j = 0; j < 10; j++) { z = j * 5 - 25; if (j != 0) { walls[i, j, 0] = makeWall(x, z, true); } if (i != 0) { walls[i, j, 1] = makeWall(x, z, false); } } } ; } System.Random rng = new System.Random(); Vector2[] dirs = //Adjacent Node Directions { new Vector2(0, -1), new Vector2(0, 1), new Vector2(1, 0), new Vector2(-1, 0) }; HashSet <Vector2> visited = new HashSet <Vector2>(); //Holds Visited Nodes List <Vector2> deadends = new List <Vector2>(); //Holds Dead Ends Stack <Vector2> stack = new Stack <Vector2>(); //Holds Backtrack Worthy Nodes Vector2 current = new Vector2(0, 0); //Start node visited.Add(current); List <Vector2> options = new List <Vector2>(); //Holds Viable Directions Vector2 adj; //Temp for Node in Direction Vector2 choice; //Selected Directions while (true) //Still options left { /* Loads in Viable Directions */ options.Clear(); for (int i = 0; i < dirs.Length; i++) { adj = current + dirs[i]; if (!visited.Contains(adj) && adj.x >= 0 && adj.x < 10 && adj.y >= 0 && adj.y < 10) { options.Add(dirs[i]); } } if (options.Count <= 0) //Dead End { deadends.Add(current); if (stack.Count <= 0) { break; } //No Backtrack Options = Quit else { current = stack.Pop(); } //Backtrack = keep trying } else { choice = options[0]; if (options.Count > 1) //Multiple options, add to stack { stack.Push(current); choice = options[rng.Next(options.Count)];//pick random adj } if (choice.x + choice.y < 0) { Destroy(walls[(int)current.x, (int)current.y, (int)Mathf.Abs(choice.x)]); current += choice; } else { current += choice; Destroy(walls[(int)current.x, (int)current.y, (int)choice.x]); } visited.Add(current); } } /* Makes Dead ends less likely */ for (int d = 0; d < deadends.Count; d++) { current = deadends[d]; if (rng.Next(3) != 0)//remove adj wall { options.Clear(); for (int i = 0; i < dirs.Length; i++) { adj = current + dirs[i]; if (adj.x >= 0 && adj.x < 10 && adj.y >= 0 && adj.y < 10) { options.Add(dirs[i]); } } if (options.Count > 0) { choice = options[rng.Next(options.Count)];//pick random adj if (choice.x + choice.y < 0) { Destroy(walls[(int)current.x, (int)current.y, (int)Mathf.Abs(choice.x)]); } else { current += choice; Destroy(walls[(int)current.x, (int)current.y, (int)choice.x]); } } } } }