Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine;
- //RightControllerAnchor
- public class QuadCreator1_virkeIkke : MonoBehaviour
- {
- public float width = 1;
- public float height = 1;
- [SerializeField]
- private GameObject hand;
- public bool findingPoints = false;
- private Vector3[] vertices = new Vector3[4];
- private Mesh mesh;
- private int index = 0;
- public Material myMaterial;
- public GameObject myPrefab; //wand
- private GameObject instantiateObj; //wand refrence
- public GameObject markerPrefab; //marker
- public GameObject[] instantiateMarker; //markers refrence
- public void Start()
- {
- MeshRenderer meshRenderer = gameObject.AddComponent<MeshRenderer>();
- //meshRenderer.sharedMaterial = new Material(Shader.Find("Standard"));
- meshRenderer.sharedMaterial = myMaterial;
- MeshFilter meshFilter = gameObject.AddComponent<MeshFilter>();
- mesh = new Mesh();
- vertices = new Vector3[4]
- {
- new Vector3(0, 0, 0), //BOTTOM LEFT
- new Vector3(width, 0, 0),//BOTTOM RIGHT
- new Vector3(0, 0, height), //TOP LEFT
- new Vector3(width, 0, height)//TOP RIGHT
- };
- mesh.vertices = vertices;
- int[] tris = new int[6]
- {
- // lower left triangle
- 0, 2, 1,
- // upper right triangle
- 2, 3, 1
- };
- mesh.triangles = tris;
- Vector3[] normals = new Vector3[4]
- {
- -Vector3.forward,
- -Vector3.forward,
- -Vector3.forward,
- -Vector3.forward
- };
- mesh.normals = normals;
- Vector2[] uv = new Vector2[4]
- {
- new Vector2(0, 0),
- new Vector2(1, 0),
- new Vector2(0, 1),
- new Vector2(1, 1)
- };
- mesh.uv = uv;
- meshFilter.mesh = mesh;
- }
- public void Update()
- {
- if (OVRInput.GetDown(OVRInput.Button.Four) && !findingPoints)
- {
- findingPoints = true;
- instantiateObj=(GameObject) Instantiate(myPrefab, new Vector3(0, 0, 0), Quaternion.identity);
- /* for(int i = 0; i < 4; i++)
- {
- UpdateVertex(Vector3(0,0,0))
- }
- */
- }
- if (findingPoints)
- {
- instantiateObj.transform.position = hand.transform.position;
- instantiateObj.transform.rotation = hand.transform.rotation;
- instantiateObj.transform.Rotate(50, 0, 0);
- if (OVRInput.GetDown(OVRInput.Button.Three))
- {
- if (index==0)
- {
- PutMarker(instantiateObj.transform.GetChild(0).gameObject.transform.position);
- //UpdateVertex(instantiateObj.transform.GetChild(0).gameObject.transform.position);
- //UpdateMesh();
- index=index+1;
- }
- if (index >= 4) //stop mode
- {
- //index = 0;
- findingPoints = false;
- Destroy(instantiateObj);
- for (int i = 0; i < 4; i++)
- {
- Destroy(instantiateMarker[i]);
- }
- }
- }
- }
- }
- private void PutMarker(Vector3 markerPos)
- {
- instantiateMarker[index] = Instantiate(markerPrefab, markerPos, Quaternion.identity);
- }
- private void UpdateMesh()
- {
- mesh.vertices = vertices;
- }
- private void UpdateVertex(Vector3 newPosition)
- {
- vertices[index] = newPosition;
- // instantiateMarker[index] = Instantiate(markerPrefab, newPosition, Quaternion.identity);
- /*
- index++;
- if (index >= 4) //stop mode
- {
- index = 0;
- findingPoints = false;
- Destroy(instantiateObj);
- for (int i = 0; i < 4; i++)
- {
- Destroy(instantiateMarker[i]);
- }
- }*/
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement