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/WaypointCreator.cs
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
50 lines (42 sloc)
1.6 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 WaypointCreator : MonoBehaviour | |
{ | |
// How many WayPoints do we want in our game? | |
public int NumOfWayPoints = 3; | |
// | |
private GameObject FloorObj; | |
private float FloorX = 0; | |
private float FloorY = 0; | |
private GameObject WayPoint; | |
private Vector3 NewWaypoint; | |
// 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. | |
WayPoint = GameObject.FindGameObjectWithTag("Waypoint"); | |
WayPoint.SetActive(false); | |
for(int i=0; i<NumOfWayPoints; i++) | |
{ | |
//instatiates a copy of WayPoint. | |
float x = Random.Range(-40, FloorX - 60); | |
float y = Random.Range(-40, FloorY - 60); | |
//Debug.Log(x); | |
//NewWaypoint = new Vector3(x, y); | |
Vector3 NewWayPWorldPos = Camera.main.ViewportToWorldPoint(NewWaypoint); | |
NewWayPWorldPos.x = x; | |
NewWayPWorldPos.y = 0; | |
NewWayPWorldPos.z = y; | |
Instantiate(WayPoint, NewWayPWorldPos, new Quaternion(), transform).SetActive(true); | |
//Debug.Log(NewWayPWorldPos.x); | |
} | |
} | |
// Update is called once per frame | |
void Update() | |
{ | |
} | |
} |