AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
DuplicateAfterThrow.cs
Go to the documentation of this file.
1 // Copyright (c) Microsoft Corporation. All rights reserved.
2 // Licensed under the MIT License. See LICENSE in the project root for license information.
3 
4 using UnityEngine;
5 
6 namespace HoloToolkit.Unity.InputModule.Examples.Grabbables
7 {
8  public class DuplicateAfterThrow : MonoBehaviour
9  {
10  public GameObject ThrowObject;
11  private Vector3 startPos;
12  private Quaternion startRot;
13  private Color startColor;
14 
15  protected virtual void OnEnable()
16  {
17  grabbable.OnReleased += SpawnDuplicate;
18  }
19 
20  protected virtual void OnDisable()
21  {
22  grabbable.OnReleased -= SpawnDuplicate;
23  }
24 
25  protected virtual void Awake()
26  {
27  grabbable = GetComponent<BaseGrabbable>();
28  }
29 
30  private void Start()
31  {
32  startPos = transform.position;
33  startRot = transform.rotation;
34  startColor = GetComponent<Renderer>().material.color;
35  ThrowObject = gameObject;
36  }
37 
43  private void SpawnDuplicate(BaseGrabbable baseGrab)
44  {
45  GameObject thrown = Instantiate(ThrowObject, startPos, Quaternion.identity);
46  thrown.GetComponent<ThrowableObject>().ZeroGravityThrow = GetComponent<BaseThrowable>().ZeroGravityThrow;
47  thrown.GetComponent<ThrowableObject>().ThrowMultiplier = GetComponent<BaseThrowable>().ThrowMultiplier;
48  thrown.GetComponent<Renderer>().material.color = startColor;
49  thrown.GetComponent<Rigidbody>().useGravity = true;
50  thrown.transform.rotation = startRot;
51  }
52 
53  private BaseGrabbable grabbable;
54  }
55 }
Extends its behaviour from BaseThrowable. This is a non-abstract script that can be attached to throw...
//Intended Usage// Attach a "grabbable_x" script (a script that inherits from this) to any object tha...