コード例 #1
0
    /// <summary>
    /// definies the behavior of the icebock on a push. this function will check if the iceblock should be moving or should be destroyed
    /// </summary>
    /// <param name="pusherPosition">the position of the object who wants to move the iceblock</param>
    public void push(Vector3 pusherPosition)
    {
        Debug.Log("Push Called!");

        //if (world == null && worldMockUp != null)
        //    // Find info for movement from world;
        //    destinationForSlide = worldMockUp.getDestinationForIceblock(this, pusherPosition);
        //else if (world == null)
        //    throw new Exception("You must call \"ThisIsMe\" after creating this object or the movement won't work!");
        //else
        //    // Find info for movement from world;

        /*
         *  //destinationForSlide = world.getDestinationForIceblock(this, pusherPosition);
         *
         * // if destination is the same as position destroy block;
         * velocity = speedOfIceBlock * (destinationForSlide - transform.position).normalized; // check for 0
         * if (testDestroing)
         * {
         *  testDestroing = !testDestroing;
         *  velocity = new Vector3(0, 0, 0);
         * }
         * String dbgmsg = String.Format("velocity({0}, {1}, {2})", velocity.x, velocity.y, velocity.z);
         * Debug.Log(dbgmsg);
         * if (velocity.x == 0f && velocity.y == 0f && velocity.z == 0f)
         * {
         *  Debug.Log("Start destroing!");
         *  this.DoDestroy();
         * }
         * else
         * {
         *  currentState = IceBlockState.Moving;
         * }
         */
        if (world.canMove(this, pusherPosition))
        {
            //todo: DestinationForSlide must be changed, this one is not working
            destinationForSlide = world.getDestinationForIceblockMoving(this, pusherPosition);
            velocity            = speedOfIceBlock * (destinationForSlide - transform.position).normalized; // check for 0
            //todo: Destination should be a natural number only for straight moving
            currentState = IceBlockState.Moving;
        }
        else
        {
            currentState = IceBlockState.Destroying;
        }
    }