/// <summary>
    /// Update is called once per frame
    /// </summary>
    void Update()
    {
        CheckForTest();

        switch (currentState)
        {
        case IceBlockState.Still:
            // dont do anything
            break;

        case IceBlockState.Destroying:
            //todo: destroying the iceblock
            break;

        case IceBlockState.Moving:
            transform.position += velocity * Time.deltaTime;
            //if this state is moving then do:
            //question for finals: how to check for direction, how to normalize a vector, how to smoth move an object
            //vector3.dot check for 0, - or + for direction and going over destination
            //if direction change, stop moving (and jump to destination if over?)
            if (DestinationReached())
            {
                Debug.Log("DestinationReached!");
                currentState       = IceBlockState.Still;
                transform.position = destinationForSlide;
            }
            break;
        }
    }
    /// <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
        currentState = IceBlockState.Moving;
    }
Example #3
0
 public Vector3 GetIceBlock(ref IceBlockState callback)
 {
     callback = GetIceBlockState; return(GetIceBlockPosition);
 }