Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Zombie-Shooter/Walls.cs
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
47 lines (40 sloc)
1.48 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class Walls : MonoBehaviour | |
{ | |
// How many Walls do we want in our game? | |
public int NumOfWalls = 10; | |
// | |
private GameObject FloorObj; | |
private float FloorX = 0; | |
private float FloorY = 0; | |
private GameObject Wall; | |
private Vector3 NewWall; | |
// Start is called before the first frame update | |
void Start() | |
{ | |
FloorObj = GameObject.FindGameObjectWithTag("Floor"); | |
FloorX = FloorObj.GetComponent<MeshFilter>().mesh.bounds.size.x * FloorObj.transform.localScale.x; | |
FloorY = FloorObj.GetComponent<MeshFilter>().mesh.bounds.size.y * FloorObj.transform.localScale.y; | |
// create Number of Way points on the floor. | |
Wall = GameObject.FindGameObjectWithTag("Wall"); | |
Wall.SetActive(false); | |
for (int i = 0; i < NumOfWalls; i++) | |
{ | |
//instatiates a copy of WayPoint. | |
float x = Random.Range(-30, FloorX - 80); | |
float y = Random.Range(-30, FloorY - 80); | |
Vector3 NewWallWorldPos = Camera.main.ViewportToWorldPoint(NewWall); | |
NewWallWorldPos.x = x; | |
NewWallWorldPos.y = 2; | |
NewWallWorldPos.z = y; | |
Instantiate(Wall, NewWallWorldPos, new Quaternion(), transform).SetActive(true); | |
//Debug.Log(NewWayPWorldPos.x); | |
} | |
} | |
// Update is called once per frame | |
void Update() | |
{ | |
} | |
} |