예제 #1
0
	void LoopList () {
		
		// For the path behaviour.
		if (loopBehaviour == LoopBehaviourType.Path)
		{
			
			// Return if we are on the last path waypoint.
			if (currentDestination > wayPoints.Count-1)
			{
				
				// Set to complete.
				loopStatus = LoopStatusType.CycelComplete;
				return;
			}
		}	
		// Check if direction is stop.
		if (direction == DirectionType.Stop)
		{
			
			// Reset the counter.
			currentDestination = 0;
			
			// It was, no need to continue
			return;
		}
		
		// Check if the cycle is complete.
		if (loopStatus == LoopStatusType.CycelComplete)
		{
			// It was, restart if allowed
			if (loopBehaviour != LoopBehaviourType.Once)
			
				// Get it moving again.
				loopStatus = LoopStatusType.Moving;

			// For the loop behaviour.
			if (loopBehaviour == LoopBehaviourType.Loop)
			{
				
				// If we are looping backwords to the top.
				if (direction == DirectionType.Backward)
				
					// Set the new destination.
					currentDestination = (wayPoints.Count -1 );
					
				// If we are looping forwards to begining.
				else if (direction == DirectionType.Forward)
				
					// Set a new destination.
					currentDestination = 0;
					
				//If non of these then there is an error
				else
				
					// Error
					Debug.LogError ("Error, unsupported direction for strafe behaviour!");
				
				// Our work is done here. Return!
				return;
			}
			
			// For the strafe behaviour.
			else if (loopBehaviour == LoopBehaviourType.Strafe)
			{
				// Toggle between forward and backward.
				if (direction == DirectionType.Backward)
				
					// Toggle.
					{direction = DirectionType.Forward; currentDestination++;}

				// Toggle between backward and forward.
				else if (direction == DirectionType.Forward)
				
					// Toggle.
					{direction = DirectionType.Backward; currentDestination--;}	
				
				// Unless non of these sates then there	is an error.
				else
				
					// Error.
					Debug.LogError ("Error, unsupported direction for strafe behaviour!");
			
				// Return since nothing to do left.
				return;
			}
			
			// For the loop and path once behaviour.
			else if (loopBehaviour == LoopBehaviourType.Once ||loopBehaviour == LoopBehaviourType.Path )
				
				// Stop all movement
				direction = DirectionType.Stop;
			// Behaviour was not supported.
			else
			
				// Error.
				Debug.LogError ("Error, unsuported behaviour!");
		}	
		
		// Check if we are going forward.
		if (direction == DirectionType.Forward)
		
			// increment the counter "forward".
			currentDestination++;
		
		// Otherwise check if we are going backward.
		else if (direction== DirectionType.Backward)
		
			// increment check if we are going.
			currentDestination--;
	}
예제 #2
0
	// Update is called once per frame
	void Update () {

		// Check if waypoint exists.
		if ( wayPoints.Count > currentDestination && currentDestination > -1)
		{
			// Only move if NOT stopped.
			if (direction != DirectionType.Stop)
			
				// Do the movement.
				transform.position = Vector3.Lerp (transform.position, wayPoints[currentDestination].transform.position, Time.deltaTime * speed);
		}
		else
		{
			// Set the cycel to complete as moving to a non existing waypoint is imposible.
			loopStatus = LoopStatusType.CycelComplete;
			
			// Look what to do next.
			LoopList();
		}
		
		
	}