This repository has been archived by the owner on Sep 17, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WeaponSelector.cs
103 lines (97 loc) · 3.57 KB
/
WeaponSelector.cs
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using VRTK;
using VRTK.Examples;
public class WeaponSelector : MonoBehaviour {
public VRTK_InteractableObject sword;
public VRTK_InteractableObject wand;
public VRTK_InteractableObject bow;
public GameObject LController;
public GameObject RController;
public GameObject arrowSpawner;
private VRTK_InteractGrab lgrab;
private VRTK_InteractGrab rgrab;
private GameObject weapon;
private VRTK_ObjectAutoGrab autograb;
private VRTK_ControllerEvents controllerevents;
public VRTK_ControllerEvents othercontroller;
private VRTK_InteractableObject currentWeapon;
private MovementSwitch move;
private Wand wandscript;
private Sword swordscript;
private bool isItASword;
// Use this for initialization
void Start () {
lgrab = LController.GetComponent<VRTK_InteractGrab>();
rgrab = RController.GetComponent<VRTK_InteractGrab>();
autograb = RController.GetComponent<VRTK_ObjectAutoGrab>();
arrowSpawner.SetActive(false);
isItASword = true;
swordscript = sword.GetComponent<Sword>();
swordscript.LController = LController;
swordscript.RController = RController;
}
// Update is called once per frame
void Update () {
wandscript = wand.GetComponent<Wand>();
if (lgrab.GetGrabbedObject() != null)
{
weapon = lgrab.GetGrabbedObject();
controllerevents = RController.GetComponent<VRTK_ControllerEvents>();
wandscript.controller = LController.GetComponent<VRTK_ControllerEvents>();
swordscript.controllerEvents = LController.GetComponent<VRTK_ControllerEvents>();
}
else
{
weapon = rgrab.GetGrabbedObject();
controllerevents = RController.GetComponent<VRTK_ControllerEvents>();
wandscript.controller = RController.GetComponent<VRTK_ControllerEvents>();
swordscript.controllerEvents = RController.GetComponent<VRTK_ControllerEvents>();
}
if (controllerevents == null)
{
VRTK_Logger.Error(VRTK_Logger.GetCommonMessage(VRTK_Logger.CommonMessageKeys.REQUIRED_COMPONENT_MISSING_FROM_GAMEOBJECT, "VRTK_ControllerEvents_ListenerExample", "VRTK_ControllerEvents", "the same"));
return;
}
controllerevents.ButtonTwoPressed += DoButtonTwoPressed;
controllerevents.ButtonTwoReleased += DoButtonTwoReleased;
}
private void DoButtonTwoPressed(object sender, ControllerInteractionEventArgs e)
{
autograb.enabled = false;
if (weapon.tag == "Sword")
{
autograb.objectToGrab = wand;
isItASword = false;
}
else if (weapon.tag == "Wand")
{
autograb.objectToGrab = bow;
arrowSpawner.SetActive(true);
}
else if (weapon.tag == "Bow")
{
autograb.objectToGrab = sword;
arrowSpawner.SetActive(false);
isItASword = true;
}
if (weapon != null)
{
if (lgrab.GetGrabbedObject() != null)
{
lgrab.ForceRelease();
Destroy(weapon);
}
else
{
rgrab.ForceRelease();
Destroy(weapon);
}
}
}
private void DoButtonTwoReleased(object sender, ControllerInteractionEventArgs e)
{
autograb.enabled = true;
}
}