- Home /
TapToPlace issue
I have a cylinder with a box collider and attached to it two scripts, "TapToPlace" and "Deformation". 1- The TapToPlace script is the one in HoloToolkit-Unity-2017.2.1.3. 2- The Deformation script I wrote it.
using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.XR.WSA.Input;
public class Deformation : MonoBehaviour { //cylinder's position Vector3 tempPos;
//cylinder's scale
Vector3 tempScale;
IEnumerator ExecuteAfterTime(float time)
{
yield return new WaitForSecondsRealtime(time);
// Code to execute after the delay
//changing the y scale to return to the original size
tempScale.y = 0.2f;
transform.localScale = tempScale;
}
private void InteractionManager_SourceUpdated(InteractionSourceUpdatedEventArgs hand)
{
//checking if the input is your hand
if (hand.state.source.kind == InteractionSourceKind.Hand)
{
//initializing hand position
Vector3 handPosition;
hand.state.sourcePose.TryGetPosition(out handPosition);
//cylinder's range
float minXRange = (transform.position.x) - ((transform.localScale.x) / 2);
float maxXRange = (transform.position.x) + ((transform.localScale.x) / 2);
float minYRange = (transform.position.y) - ((transform.localScale.y) / 2);
float maxYRange = (transform.position.y) + ((transform.localScale.y) / 2);
float minZRange = (transform.position.z) - ((transform.localScale.z) / 2);
float maxZRange = (transform.position.z) + ((transform.localScale.z) / 2);
//hand x, y and z co-ordinates
float handX = handPosition.x;
float handY = handPosition.y;
float handZ = handPosition.z;
//if my hand is on the cylinder's surface
if ((minXRange <= handX) && (handX <= maxXRange) && (minYRange <= handY) && (handY <= maxYRange) && (minZRange <= handZ) && (handZ <= maxZRange))
{
//changing the y scale to be equal to my hand position
tempScale.y = handPosition.y;
transform.localScale = tempScale;
}
else
{
StartCoroutine(ExecuteAfterTime(2f));
}
}
}
// Use this for initialization
void Start()
{
//initializing cylinder's position
tempPos = transform.position;
//initializing cylinder's scale
tempScale = transform.localScale;
InteractionManager.InteractionSourceUpdated += InteractionManager_SourceUpdated;
}
// Update is called once per frame
void Update()
{
}
}
The problem is that when I attach the Deformation script alone it works fine while when I attach both scripts only the Tap To Place script works. PS: The same problem happens when I use HandDraggble script. Any idea what is the problem? Thank you.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Restricting movement with Mathf.Clamp 4 Answers
How can i prevent from mouse to collide with thirdpersoncontroller ? 0 Answers
How to Find gameObject child. 3 Answers