示例#1
0
    // Update is called once per frame
    void Update()
    {
		if(dir!=Monk.Direction.None)
		{
			GetComponent<Monk>().Move(dir);
		}
        if (step < dirs.Length) {
            Vector3 diff = target - transform.position;
            float distanceFromPartialTarget = float.MaxValue;
            switch (dirs[step])
            {
                case Monk.Direction.Right:
                case Monk.Direction.Left:
                    distanceFromPartialTarget = diff.x;
                    break;
                case Monk.Direction.Up:
                case Monk.Direction.Down:
                    distanceFromPartialTarget = diff.y;
                    break;
            }
            if (Mathf.Abs(distanceFromPartialTarget) < monk.speed * 2)
            {
                step++;
                if (step < dirs.Length)
                {
                    dir = dirs[step];
                }
                else
                {
					dir = Monk.Direction.None;
                    monk.Stop();
                }
            }
        }
    }
示例#2
0
 void OnEnable()
 {
     target = GameMgr.instance.getRandomPos(monk.color);        
     bool horizontalThenVertical = (Random.value < 0.5);
     dirs = new Monk.Direction[2];
     Vector3 diff = target - transform.position;
     if (diff.x > 0)
     {
         dirs[horizontalThenVertical ? 0 : 1] = Monk.Direction.Right;
     }
     else
     {
         dirs[horizontalThenVertical ? 0 : 1] = Monk.Direction.Left;
     }
     if (diff.y > 0)
     {
         dirs[horizontalThenVertical ? 1 : 0] = Monk.Direction.Up;
     }
     else
     {
         dirs[horizontalThenVertical ? 1 : 0] = Monk.Direction.Down;
     }
     step = 0;
     dir = dirs[0];
 }
示例#3
0
    // Update is called once per frame
    void Update()
    {
		if(dir!=Monk.Direction.None)
		{
			GetComponent<Monk>().Move(dir);
		}
        if (framesBeforeNextCheck <= 0)
        {
            dir = AfterTurnDirection();
            framesBeforeNextCheck = Random.Range(minTurnCheckPeriod, maxTurnCheckPeriod);
        }
        else
        {
            framesBeforeNextCheck--;
        }
    }
示例#4
0
    // Update is called once per frame
    void Update()
    {
		if(dir!=Monk.Direction.None)
		{
			GetComponent<Monk>().Move(dir);
		}
        if (framesBeforeChange > 0)
        {
            framesBeforeChange--;
        }
        else
        {
            marching = !marching;
            if (marching)
            {
                switch (Random.Range(0, 4))
                {
                    case 0:
                        dir = Monk.Direction.Left;
                        break;
                    case 1:
                        dir = Monk.Direction.Right;
                        break;
                    case 2:
                        dir = Monk.Direction.Up;
                        break;
                    case 3:
                        dir = Monk.Direction.Down;
                        break;
                }
                framesBeforeChange = Random.Range(shortestMarch, longestMarch);
            }
            else
            {
				dir = Monk.Direction.None;
                GetComponent<Monk>().Stop();
                framesBeforeChange = Random.Range(shortestStop, longestStop);
            }

        }
    }
示例#5
0
	void OnDisable()
	{
		dir = Monk.Direction.None;
	}