Delete basicspawner.cs

parent fa1d3c01
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR.ARFoundation;
using UnityEngine.Experimental.XR;
using System;
public class basicspawner : MonoBehaviour
{
public GameObject targetimg;
private GameObject modeltoplace;
private ARSessionOrigin arOrigin;
private ARRaycastManager rayCAst;
private Pose placepose;
private bool hitvalid = false;
// Start is called before the first frame update
void Start()
{
arOrigin = FindObjectOfType<ARSessionOrigin>();
rayCAst = FindObjectOfType<ARRaycastManager>();
}
// Update is called once per frame
void Update()
{
updateplacepose();
Updatetarget();
if (hitvalid && Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began)
{
placemodel();
}
}
private void placemodel()
{
if (variables.objtype == 1)
{
modeltoplace = Resources.Load("1") as GameObject;
Instantiate(modeltoplace, placepose.position, placepose.rotation);
}
if (variables.objtype == 2)
{
modeltoplace = Resources.Load("2") as GameObject;
Instantiate(modeltoplace, placepose.position, placepose.rotation);
}
if (variables.objtype == 3)
{
modeltoplace = Resources.Load("3") as GameObject;
Instantiate(modeltoplace, placepose.position, placepose.rotation);
}
}
private void Updatetarget()
{
if (hitvalid)
{
targetimg.SetActive(true);
targetimg.transform.SetPositionAndRotation(placepose.position, placepose.rotation);
}
else
{
targetimg.SetActive(false);
}
}
private void updateplacepose()
{
var screencenter = Camera.current.ViewportToScreenPoint(new Vector3(0.5f, 0.5f));
var hits = new List<ARRaycastHit>();
rayCAst.Raycast(screencenter, hits, UnityEngine.XR.ARSubsystems.TrackableType.Planes);
hitvalid = hits.Count > 0;
if (hitvalid)
{
placepose = hits[0].pose;
var camforward = Camera.current.transform.forward;
var camrot = new Vector3(camforward.x, 0, camforward.z).normalized;
placepose.rotation = Quaternion.LookRotation(camrot);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment