Question by
NewtoAR · Jan 25, 2021 at 03:32 PM ·
animationaugmented realityplacement
AR Object Placement and Animation Playing
public class ARTapToPlaceObject : MonoBehaviour
{
public GameObject placementIndicator;
public GameObject AnObjectToPlace;
//private ARSessionOrigin arOrigin;
private Pose PlacementPose;
private ARRaycastManager aRRaycastManager;
private bool placementPoseIsValid = false;
void Start()
{
//arOrigin = FindObjectOfType<ARSessionOrigin>();
aRRaycastManager = FindObjectOfType<ARRaycastManager>();
}
void Update()
{
UpdatePlacementPose();
UpdatePlacementIndicator();
if(placementPoseIsValid && Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began)
{
PlaceObject();
}
}
private void PlaceObject()
{
Instantiate(AnObjectToPlace, PlacementPose.position, PlacementPose.rotation);
}
private void UpdatePlacementIndicator()
{
if (placementPoseIsValid)
{
placementIndicator.SetActive(true);
placementIndicator.transform.SetPositionAndRotation(PlacementPose.position, PlacementPose.rotation);
}
else
{
placementIndicator.SetActive(false);
}
}
private void UpdatePlacementPose()
{
var screenCenter = Camera.current.ViewportToScreenPoint(new Vector3(0.5f, 0.5f));
var hits = new List<ARRaycastHit>();
aRRaycastManager.Raycast(screenCenter, hits, TrackableType.Planes);
placementPoseIsValid = hits.Count > 0;
if (placementPoseIsValid)
{
PlacementPose = hits[0].pose;
}
}
}
Hi, I wanna displace the object away from the screen instead of the indicator's location. Then when I click the next button an animation will loop for example from 0s to 10s. ( The part will move the object from outside side of the screen to the indicator's location). Next when I press next button again, animation will loop from 10s to 20s. Same goes to "previous" button.
I was wondering how should I manipulate the script as shown. For the animation playing should I do another script?
Comment