private void Update()
        {
            mTouched = JCS_Input.GetMouseButton(0);
            if (mTouched)
            {
                // A ray is an infinite line starting at an origin and going into a direction
                // For this we will use our mouse position
                Ray ray = mCamera.ScreenPointToRay(Input.mousePosition);

                RaycastHit[] hits = Physics.RaycastAll(ray, mRaycastDistance);

                foreach (RaycastHit hit in hits)
                {
                    hit.transform.gameObject.SendMessage("OnMouseDown", SendMessageOptions.DontRequireReceiver);

#if (UNITY_EDITOR)
                    if (JCS_GameSettings.instance.DEBUG_MODE)
                    {
                        // print the name of the detected transform.
                        JCS_Debug.PrintName(hit.transform);
                    }
#endif
                }
            }
        }
Exemplo n.º 2
0
        //----------------------
        // Protected Functions

        //----------------------
        // Private Functions

        /// <summary>
        /// Only check when the item start dropping.
        /// </summary>
        /// <param name="other"> collider detected. </param>
        private void TriggerDropping(Collider other)
        {
            if (mVelocity.y > 0)
            {
                return;
            }

            // meet ignore object
            JCS_ItemIgnore jcsii = other.GetComponent <JCS_ItemIgnore>();

            if (jcsii != null)
            {
                return;
            }

            JCS_Item otherItem = this.GetComponent <JCS_Item>();

            // if itself it a item, we check other is a item or not.
            if (otherItem != null)
            {
                otherItem = other.GetComponent <JCS_Item>();
                // if both are item then we dont bother
                // each other action.
                if (otherItem != null)
                {
                    return;
                }
            }

#if (UNITY_EDITOR)
            // if is debug mode print this out.
            // in order to know what does item touched and
            // stop this movement.
            if (JCS_GameSettings.instance.DEBUG_MODE)
            {
                JCS_Debug.PrintName(other.transform);
            }
#endif

            mVelocity.y = 0;
            mEffect     = false;


            mFixCollider = other;

            // TODO(JenChieh): not all the object we get set are
            //                 box collider only.
            BoxCollider beSetBox = other.GetComponent <BoxCollider>();

            // set this ontop of the other box(ground)
            if (beSetBox != null)
            {
                JCS_Physics.SetOnTopOfBoxWithSlope(mBoxCollider, beSetBox);
            }


            // enable the physic once on the ground
            JCS_PlayerManager.instance.IgnorePhysicsToAllPlayer(this.mBoxCollider, false);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Debug print name.
        /// </summary>
        /// <param name="trans"></param>
        private void PrintName(Transform trans)
        {
#if (UNITY_EDITOR)
            if (!JCS_GameSettings.instance.DEBUG_MODE)
            {
                return;
            }

            // print the name of the detected transform.
            JCS_Debug.PrintName(trans);
#endif
        }
        /// <summary>
        /// Lock a gameobject, and look at it.
        /// So the object will seems like it
        /// "approach/further away" to the object.
        /// </summary>
        /// <param name="method"> method to find. </param>
        public void LockOnInit(FindMethod method)
        {
            JCS_2DLiveObject closestliveObj = null;

            switch (method)
            {
            case FindMethod.CLOSEST:
                closestliveObj = FindClosest();
                break;

            case FindMethod.CLOSEST_RIGHT:
                closestliveObj = FindClosestRight();
                break;

            case FindMethod.CLOSEST_LEFT:
                closestliveObj = FindClosestLeft();
                break;

            case FindMethod.CLOSEST_TOP:
                closestliveObj = FindClosestTop();
                break;

            case FindMethod.CLOSEST_BOTTOM:
                closestliveObj = FindClosestBottom();
                break;
            }

            // no object found!
            if (closestliveObj == null)
            {
                return;
            }

            Vector3 newLookPoint = closestliveObj.transform.position;

            // look at the target object
            this.transform.LookAt(newLookPoint);

            // rotate back to original point.
            if (mRotateBack90)
            {
                this.transform.Rotate(0, -90, 0);
            }

            if (mAttackerInfo.Attacker != null)
            {
                if (mDirection == State.NONE)
                {
                    if (JCS_Mathf.IsNegative(mAttackerInfo.Attacker.localScale.x))
                    {
                        mDirection = State.NEGATIVE;
                    }
                    else
                    {
                        mDirection = State.POSITIVE;
                    }
                }

                // 我們規定所有的圖往一邊, 所以只檢查一邊.
                if (mDirection == State.NEGATIVE)
                {
                    this.transform.Rotate(0, 0, 180);
                }
            }

#if (UNITY_EDITOR)
            // print out the name.
            if (JCS_GameSettings.instance.DEBUG_MODE)
            {
                JCS_Debug.PrintName(closestliveObj.transform);
            }
#endif
        }