- Home /
Question by
Nabil_fx · Nov 17, 2014 at 12:39 AM ·
Restart Script help.
Ho i can reset this script on taget lost. The problem is that. The problem is when shot off target and then back to the target, the rotation of the object is not in the starting rotation, therotation is what was left. Here is both script.
This script is attact to the object__
var Objeto : GameObject;
var pivot : GameObject;
function OnEnable(){
if(!pivot){
pivot = new GameObject("Pivot");
pivot.transform.parent = transform;
}
}
function Update () {
for(var touch : Touch in Input.touches){
Objeto.transform.RotateAround(pivot.transform.position, new Vector3(0,1,0), touch.deltaPosition.y);
}
}
function OnDrawGizmos(){
if(pivot){
Gizmos.color = new Color(0.0,1,0.0);
Gizmos.DrawRay(pivot.transform.position, new Vector3(0,.2,0));
Gizmos.color = new Color(0.0,0.0,1);
Gizmos.DrawRay(pivot.transform.position - new Vector3(0.2,0,0), new Vector3(0.4,0,0));
Gizmos.color = new Color(1,0.0,0.0);
Gizmos.DrawRay(pivot.transform.position - new Vector3(0.0,0,0.2), new Vector3(0,0,0.4));
}
}
This is my DefaultTrackablerEventHandler
/*==============================================================================
Copyright (c) 2010-2014 Qualcomm Connected Experiences, Inc.
All Rights Reserved.
Confidential and Proprietary - Qualcomm Connected Experiences, Inc.
==============================================================================*/
using UnityEngine;
/// <summary>
/// A custom handler that implements the ITrackableEventHandler interface.
/// </summary>
public class DefaultTrackableEventHandler : MonoBehaviour,
ITrackableEventHandler
{
#region PRIVATE_MEMBER_VARIABLES
private TrackableBehaviour mTrackableBehaviour;
#endregion // PRIVATE_MEMBER_VARIABLES
#region UNTIY_MONOBEHAVIOUR_METHODS
void Start()
{
mTrackableBehaviour = GetComponent<TrackableBehaviour>();
if (mTrackableBehaviour)
{
mTrackableBehaviour.RegisterTrackableEventHandler(this);
}
}
#endregion // UNTIY_MONOBEHAVIOUR_METHODS
#region PUBLIC_METHODS
/// <summary>
/// Implementation of the ITrackableEventHandler function called when the
/// tracking state changes.
/// </summary>
public void OnTrackableStateChanged(
TrackableBehaviour.Status previousStatus,
TrackableBehaviour.Status newStatus)
{
if (newStatus == TrackableBehaviour.Status.DETECTED ||
newStatus == TrackableBehaviour.Status.TRACKED ||
newStatus == TrackableBehaviour.Status.EXTENDED_TRACKED)
{
OnTrackingFound();
}
else
{
OnTrackingLost();
}
}
#endregion // PUBLIC_METHODS
#region PRIVATE_METHODS
private void OnTrackingFound()
{
Renderer[] rendererComponents = GetComponentsInChildren<Renderer>(true);
Collider[] colliderComponents = GetComponentsInChildren<Collider>(true);
Animation[] animationComponents = GetComponentsInChildren<Animation>();
foreach (Animation animation in animationComponents)
{
foreach (AnimationState animState in animation)
{
animState.speed = 1f;
animation.Play();
}
}
// Enable rendering:
foreach (Renderer component in rendererComponents)
{
component.enabled = true;
}
// Enable colliders:
foreach (Collider component in colliderComponents)
{
component.enabled = true;
}
Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " found");
}
private void OnTrackingLost()
{
Renderer[] rendererComponents = GetComponentsInChildren<Renderer>(true);
Collider[] colliderComponents = GetComponentsInChildren<Collider>(true);
Animation[] animationComponents = GetComponentsInChildren<Animation>();
foreach (Animation animation in animationComponents)
{
foreach (AnimationState animState in animation)
{
animState.speed = 0f;
animation.Stop();
}
}
// Disable rendering:
foreach (Renderer component in rendererComponents)
{
component.enabled = false;
}
// Disable colliders:
foreach (Collider component in colliderComponents)
{
component.enabled = false;
}
Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " lost");
}
#endregion // PRIVATE_METHODS
}
Comment
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Animation Not Playing 1 Answer
3D Gravity towards one object 3 Answers
How do i put lights with muzzleflash? 1 Answer
How to Load from an external file, sound 0 Answers