Exemple #1
0
    void Update()
    {
        if (moving)
        {
            float distance = (ownTransform.position - new Vector3(x, y, ownTransform.position.z)).magnitude;

            if (distance < 0.3 && stepObjectWorldInteraction != null)
            {
                stepObjectWorldInteraction.interact();
                stepObjectWorldInteraction = null;
            }

            float xDir = (float)x - ownTransform.position.x;
            float yDir = (float)y - ownTransform.position.y;
            if (distance < moveSpeed * Time.deltaTime * 1.1)               // 1.1 is a magic number to prevent bugs from floating point errors
            {
                ownTransform.position = new Vector3((float)x, (float)y, ownTransform.position.z);
                moving = false;
            }
            else
            {
                ownTransform.position += new Vector3(xDir, yDir).normalized *moveSpeed *Time.deltaTime;
            }
        }
    }
Exemple #2
0
 void Start()
 {
     ownTransform   = this.transform;
     gameController = GameObject.FindGameObjectWithTag("GameController");
     movementGrid   = (Grid)gameController.GetComponent <Grid> ();
     if (movementGrid.getPosition(x, y) != null)
     {
         stepObject = movementGrid.getPosition(x, y).stepOn;
     }
     if (stepObject != null)
     {
         WorldInteraction stepObjectWorldInteraction = stepObject.GetComponent <WorldInteraction> ();
         stepObjectWorldInteraction.interact();
         stepObjectWorldInteraction = null;
     }
     anim = this.gameObject.GetComponent <AnimationLoop> ();
 }