WeaponLoader.cs
1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System.Collections;
using System.Collections.Generic;
using UnityEngine.XR.ARKit;
using UnityEngine.XR.ARFoundation;
using UnityEngine;
public class WeaponLoader : MonoBehaviour
{
public GameObject _objectToBeInstantiated; // object that is going to be instantiated = prefabs
public Vector3 position;
Vector3 cam_pos;
GameObject cam;
GameObject weapon;
// Start is called before the first frame update
void Start()
{
cam = GameObject.Find("AR Camera");
cam_pos = cam.transform.position;
if(cam != null)
{
Debug.Log("cam attatched ");
}
Debug.Log(cam_pos.ToString());
}
// Update is called once per frame
void Update()
{
if (!weapon)
{
weapon = Instantiate<GameObject>(_objectToBeInstantiated, cam_pos - position, new Quaternion(0, 0, 0, 0));
}
else
{
cam_pos = cam.transform.position;
if (weapon.transform.position != cam_pos)
{
weapon.transform.position = cam.transform.position - position;
weapon.transform.rotation = cam.transform.rotation;
}
}
}
}