Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Merger : MonoBehaviour {
- // Use this for initialization
- void Start () {
- // fetch all mesh filters of objects tagged as floor
- List<MeshFilter> meshFilters = new List<MeshFilter>();
- GameObject[] floorObjects = GameObject.FindGameObjectsWithTag ("floor");
- foreach (GameObject curFloor in floorObjects)
- {
- meshFilters.Add (curFloor.GetComponent<MeshFilter> ());
- }
- // Make a combine instance for all the mesh filters
- CombineInstance[] combine = new CombineInstance[meshFilters.Count];
- // Loop through all the mesh filters to assign to the combine instance
- for(int i = 0; i < meshFilters.Count; i++)
- {
- // Set the mesh for this combine instance
- combine[i].mesh = meshFilters[i].sharedMesh;
- // Set the transform for this combine instance
- combine[i].transform = meshFilters[i].transform.localToWorldMatrix;
- // Set the old object to inactive (ROB you might not want to do this as it will delete your old floor,
- // which isnt what you want as you want this to basically be an invisible overlay right?)
- meshFilters[i].gameObject.SetActive(false);
- }
- // Make a new mesh for this parent object
- transform.GetComponent<MeshFilter>().mesh = new Mesh();
- // Combine the meshes using the combine instance
- transform.GetComponent<MeshFilter>().mesh.CombineMeshes(combine);
- // Set this new object to active
- transform.gameObject.SetActive(true);
- // Here you might wanna adjust the positioning of this new object, and add the SteamVR floor script to this object
- // also might want to hide the mesh so its not visible or whatever you need to do?
- transform.position = new Vector3(0,0,0);
- gameObject.AddComponent<TeleportArea> ();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement