Exemple #1
0
 void Start()
 {
     camMain         = Camera.main;
     pullState       = PullState.Idle;
     posPullingStart = pullingStartPoint.position;
     initPos         = PosThrowTarget;
 }
Exemple #2
0
        private void SwitchStates()
        {
            switch (pullState)
            {
            case PullState.Idle:

                if (Input.GetMouseButtonDown(0))
                {
                    //get the point on screen user has tapped
                    Vector3 location = camMain.ScreenToWorldPoint(Input.mousePosition);
                    //if user has tapped onto the ball
                    if (throwObj.Collider == Physics2D.OverlapPoint(location))
                    {
                        pullState = PullState.UserPulling;
                    }
                }
                break;

            case PullState.UserPulling:

                dotHelper.gameObject.SetActive(true);

                if (Input.GetMouseButton(0))
                {
                    //get touch position
                    Vector3 posMouse = camMain.ScreenToWorldPoint(Input.mousePosition);
                    posMouse.z = 0;
                    //we will let the user pull the ball up to a maximum distance
                    if (Vector3.Distance(posMouse, posPullingStart) > maxDistance)
                    {
                        Vector3 maxPosition = (posMouse - posPullingStart).normalized * maxDistance + posPullingStart;
                        maxPosition.z      = dotHelper.position.z;
                        dotHelper.position = maxPosition;
                    }
                    else
                    {
                        posMouse.z         = dotHelper.position.z;
                        dotHelper.position = posMouse;
                    }

                    float distance = Vector3.Distance(posPullingStart, dotHelper.position);
                    trajCtrl.DisplayTrajectory(distance);
                }
                else    //user has removed the tap
                {
                    float distance = Vector3.Distance(posPullingStart, dotHelper.position);
                    trajectoryLineRen.enabled = false;
                    ThrowObj(distance);
                }
                break;

            default:
                break;
            }
        }
Exemple #3
0
        /// <summary>
        /// Restart thrown object states, clear trail
        /// </summary>
        /// <param name="posThrownObj"></param>
        public void Restart(Vector3 posThrownObj)
        {
            trail.emit = false;
            trail.Clear();

            StartCoroutine(ClearTrail());

            trajectoryLineRen.enabled = false;
            dotHelper.gameObject.SetActive(false);
            pullState = PullState.Idle;

            throwObj.Reset(posThrownObj);
        }
Exemple #4
0
        //private Vector2 velocityToRg = Vector2.zero;
        private void ThrowObj(float distance)
        {
            Debug.Log("ThrowObj");

            pullState = PullState.Idle;
            Vector3 velocity = posPullingStart - dotHelper.position;

            //velocityToRg = CalcVelocity(velocity, distance);

            throwObj.ThrowObj(CalcVelocity(velocity, distance));
            //rgThrowTarget.velocity = velocityToRg;
            //rgThrowTarget.isKinematic = false;

            trail.enabled = true;
            trail.emit    = true;
            dotHelper.gameObject.SetActive(false);
        }
Exemple #5
0
    public PullState OnStateChange(PullState ps)
    {
        switch(ps)
        {
            case PullState.Idle:
                currentRate = 0;
                break;

            case PullState.BeingPulled:
                currentRate = pullRate;
                break;

            case PullState.FullExtended:
                canBeGrabbed = false;
                currentRate = 0;
                break;

            case PullState.Retracting:
                currentRate = retractRate;
                break;
        }

        return ps;
    }
Exemple #6
0
 public PullResult RemoveState(PullState state)
 {
     Status = (Status | state) ^ state;
     return(this);
 }
Exemple #7
0
 public PullResult AddState(PullState state)
 {
     Status = Status | state;
     return(this);
 }
 public void DestroyInSec( float _Sec )
 {
     m_DestroyTimer.Setup( _Sec ) ;
     m_DestroyTimer.Rewind() ;
     m_State = PullState.WaitToDestroy ;
 }
 // Update is called once per frame
 void Update()
 {
     switch( m_State )
     {
     case PullState.UnActive :
         break ;
     case PullState.Active :
         KeepPull() ;
         break ;
     case PullState.WaitToDestroy :
         if( true == m_DestroyTimer.IsCountDownToZero() )
         {
             m_State = PullState.Dead ;
         }
         KeepPull() ;
         break ;
     case PullState.Dead :
         Component.Destroy( this ) ;
         break ;
     }
 }
    public void Setup( GameObject _TargetUnit , 
					   float _MinMaintainDistance ,
					   float _MaxMaintainDistance ,
					   float _PullMaxSpeed )
    {
        m_TargetUnit = _TargetUnit ;
        m_MinMaintainDistance = _MinMaintainDistance ;
        m_MaxMaintainDistance = _MaxMaintainDistance ;
        m_PullMaxSpeed = _PullMaxSpeed ;
        m_State = PullState.Active ;
    }