Advertisement
MrBotox

Untitled

Apr 19th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.78 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Merger : MonoBehaviour {
  6.  
  7.     // Use this for initialization
  8.     void Start () {
  9.         // fetch all mesh filters of objects tagged as floor
  10.         List<MeshFilter> meshFilters = new List<MeshFilter>();
  11.         GameObject[] floorObjects = GameObject.FindGameObjectsWithTag ("floor");
  12.  
  13.         foreach (GameObject curFloor in floorObjects)
  14.         {
  15.             meshFilters.Add (curFloor.GetComponent<MeshFilter> ());
  16.         }
  17.  
  18.         // Make a combine instance for all the mesh filters
  19.         CombineInstance[] combine = new CombineInstance[meshFilters.Count];
  20.  
  21.         // Loop through all the mesh filters to assign to the combine instance
  22.         for(int i = 0; i < meshFilters.Count; i++)
  23.         {
  24.             // Set the mesh for this combine instance
  25.             combine[i].mesh = meshFilters[i].sharedMesh;
  26.             // Set the transform for this combine instance
  27.             combine[i].transform = meshFilters[i].transform.localToWorldMatrix;
  28.             // Set the old object to inactive (ROB you might not want to do this as it will delete your old floor,
  29.             // which isnt what you want as you want this to basically be an invisible overlay right?)
  30.             meshFilters[i].gameObject.SetActive(false);
  31.         }
  32.            
  33.         // Make a new mesh for this parent object
  34.         transform.GetComponent<MeshFilter>().mesh = new Mesh();
  35.         // Combine the meshes using the combine instance
  36.         transform.GetComponent<MeshFilter>().mesh.CombineMeshes(combine);
  37.         // Set this new object to active
  38.         transform.gameObject.SetActive(true);
  39.  
  40.         // Here you might wanna adjust the positioning of this new object, and add the SteamVR floor script to this object
  41.         // also might want to hide the mesh so its not visible or whatever you need to do?
  42.         transform.position = new Vector3(0,0,0);
  43.         gameObject.AddComponent<TeleportArea> ();
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement