Skip to content
Permalink
master
Switch branches/tags

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?
Go to file
 
 
Cannot retrieve contributors at this time
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()
{
}
}