问题
I'm using Vuforia and unity for my AR App. which has more than 2 models/image targets. To zoom in and out I used Lean Touch. But the problem is both will get zoom on pinching . I want only one to zoom which is currently detected.. OR I want reset Scale component of my 3D model/models on OnTrackingLost() function in DefaultTrackableEventHandler so that when it detects other one it shows on original scale (as i set max sim images detected to one). Thanks !
EDIT :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class rscale : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetKey (KeyCode.V)) {
transform.localScale = new Vector3 (4f, 4f, 4f);
Debug.Log("scaling to 4");
}
}
}
BUT THIS SIMPLE SCRIPT IS ALSO NOT WORKING ?
回答1:
Your method doing the scaling, add :
if(this.gameObject.activeSelf == false){ return; }
// Scaling process
So if you run the code on all objects, only the active ones will be affected. Considering you deactivate the object on lost tracking.
回答2:
The trouble here is that Vuforia doesn't deactivate the 3D object attached to the image target, it only deactivates his renderer component and the colliders so you can't put a filter asking for the active state of the game object as @Everts sugest.
Instead you can have an script where you have a public reference to both 3D game objects and a method where you set the scale of both objects to one, every time you lost your image target you should call that function and both game objects will be his scale set to one.
Another solutios is, Vuforia knows wich marker found so when you detect a marker you can activate set that game object to be the one to suffer the scale efects.
来源:https://stackoverflow.com/questions/42985000/reset-scaling-of-models-in-image-target-in-unity-and-vuforia