using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System.Collections.Generic;
using System.IO;
//Perlin Noise Agents v1.0 - Spawn Behavior Class
//--Class Controls the enabling and disabling of the Spawn Map Texture and display--Class is a component of the Spawn_Geometry Game Object which contains a single mesh quad
//Mode Lab - Written by Luis Quinones
public class SpawnBehavior : MonoBehaviour {
    public GameObject plane;
    private Renderer rend;
    public Texture2D text;
    public Scrollbar toggleImage;
    private bool turnOn;
    private float toggleImageVal;
    public string newPath;
    public bool runIt;
    void Start () {
        if (runIt) {    
            runIt = false;
            turnOn = false;
            plane.GetComponent<MeshRenderer> ().enabled = false; //Turns off mesh rendered component to keep mesh hidden
            rend = GetComponent<Renderer> ();
            text = new Texture2D (1024, 768); //Creates a new texture with the specified pixels
            toggleImage.onValueChanged.AddListener (delegate {
                toggleImageVal = toggleImage.value; //Checks if we changed the scrollbar to display the mesh and texture
            if (newPath.Length != 0) {        
                var bytes = File.ReadAllBytes (newPath);
                text.LoadImage (bytes);//Loads image                
                rend.material.mainTexture = text;//Assigns it to instance of material
                turnOn = true; //Turns on the mesh and texture            
            } else {    
    void Update () {
        if (runIt) {
        //turns on and off the mesh based on the display scrollbar value which has a listener attached to it in the start function
        if (Mathf.RoundToInt(toggleImageVal) == 1) {
            plane.GetComponent<MeshRenderer> ().enabled = true;
            //plane.GetComponent<MeshCollider> ().enabled = true;
        } else {
            plane.GetComponent<MeshRenderer> ().enabled = false;
            //plane.GetComponent<MeshCollider> ().enabled = false;
  • Share