Exemple #1
0
    // Update is called once per frame
    void Update()
    {
#if UNITY_EDITOR   //we will only use this script on the editor side, though there is nothing that would prevent it from working on device
        if (Input.GetMouseButtonDown(0))
        {
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            //we'll try to hit one of the plane collider gameobjects that were generated by the plugin
            //effectively similar to calling HitTest with ARHitTestResultType.ARHitTestResultTypeExistingPlaneUsingExtent
            if (Physics.Raycast(ray, out hit, maxRayDistance, collisionLayer))
            {
                //we're going to get the position from the contact point
                m_HitTransform.position = hit.point;
                Debug.Log(string.Format("x:{0:0.######} y:{1:0.######} z:{2:0.######}", m_HitTransform.position.x, m_HitTransform.position.y, m_HitTransform.position.z));

                //and the rotation from the transform of the plane collider
                m_HitTransform.rotation = hit.transform.rotation;
            }
        }
#else
        if (Input.touchCount > 0 && m_HitTransform != null)
        {
            var touch = Input.GetTouch(0);
            if (touch.phase == TouchPhase.Began || touch.phase == TouchPhase.Moved)
            {
                var     screenPosition = Camera.main.ScreenToViewportPoint(touch.position);
                ARPoint point          = new ARPoint {
                    x = screenPosition.x,
                    y = screenPosition.y
                };

                // prioritize reults types
                ARHitTestResultType[] resultTypes =
                {
                    //ARHitTestResultType.ARHitTestResultTypeExistingPlaneUsingGeometry,
                    //ARHitTestResultType.ARHitTestResultTypeExistingPlaneUsingExtent,
                    // if you want to use infinite planes use this:
                    //ARHitTestResultType.ARHitTestResultTypeExistingPlane,
                    ARHitTestResultType.ARHitTestResultTypeEstimatedHorizontalPlane,
                    //ARHitTestResultType.ARHitTestResultTypeEstimatedVerticalPlane,
                    //ARHitTestResultType.ARHitTestResultTypeFeaturePoint
                };

                foreach (ARHitTestResultType resultType in resultTypes)
                {
                    if (HitTestWithResultType(point, resultType))
                    {
                        return;
                    }
                }
            }
        }
#endif
        float distance = Vector3.Distance(targetToFollow.position, m_HitTransform.position);
        print("Distance: " + distance);
        if (distance > 0.05f)
        {
            float timeToReach = 1.0f;
            if (distance > 5)
            {
                timeToReach = 2.5f;
            }
            speed = distance / timeToReach;

            if (currentAnimationState != CatAnimationState.Walking)
            {
                currentAnimationState = CatAnimationState.Walking;
                //catimator.speed = speed;
                catimator.SetTrigger("Walk");
            }

            m_HitTransform.position = Vector3.MoveTowards(m_HitTransform.position, targetToFollow.position, Time.deltaTime * speed);
        }
        else
        {
            if (currentAnimationState != CatAnimationState.Eating)
            {
                currentAnimationState = CatAnimationState.Eating;
                //catimator.speed = 1.0f;
                catimator.SetTrigger("Eat");
            }
        }
    }
 void SetAnimation(CatAnimationState catAnimationState)
 {
     animator.SetInteger("State", (int)catAnimationState);
 }
Exemple #3
0
    public LayerMask collisionLayer = 1 << 10;  //ARKitPlane layer

    private void Start()
    {
        currentAnimationState = CatAnimationState.Idle;
        catimator.SetTrigger("Idle");
    }