Originally Posted By: Pappenheimer
Originally Posted By: Tman
Unity is great I had an issue with it's state management system, which is seemingly going to get worked out. I might just switch back to complete my project.

Anyone wanna give a script example of a function from Unity that feels comfortable for a C-Script/Lite-C user? blush

For instance, how would I write things like camera looks at me, enemy follows me, state switches from attack to flee...



Camera looks at me (all in C#):

Code:
public Transform playerPtr;


void Update()
{
  transform.LookAt(playerPtr); 
}



assign it to the camera in the editor, and drag n drop the player into the "playerPtr" field. done.

Enemy follows player is simliar:

Code:
public Transform playerPtr;


void Update()
{
  transform.LookAt(playerPtr); 
  transfor.Translate(Vector3.forward * 20); // Move enemy into his forward Vector
}



Apply to enemy, drag n drop player into the playerPtr field, done.


For statement switches, i actually always use ENUMS

Code:
private enum MoveStates
{
  ATTACK,
  FLEE,
  IDLE
}

private MoveStates moveState;

...

// If player comes too close, flee
if(Vector3.Distance(transform.position, playerPtr.position) < 1))
  moveState = MoveStates.FLEE;

...
void Update()
{
  switch(moveState)
  {
    case MoveStates.FLEE:
      transform.LookAt(playerPtr);
      transform.Translate(-Vector3.forward * 10);
      break;
  }
}




It would run away backwards, looking at the player, but just to get an idea how you would make it.

Is it that what you wanted to know?

EDIT:
i left out the class definitions and library includings, as this is genereated automatically when creating a script anyway and looks the same for almost any script anyway.

it is just a plain:

Code:
using UnityEngine;
using System.Collections;

public class scriptName : MonoBehaviour 
{
  void Start()
  {
  }

  void Update()
  {
  }
}



Last edited by Captain_Kiyaku; 03/10/10 22:58.

My Blog

"Tag und Nacht schrei ich mich heiser,
Wind weht alle Worte fort,
Tag und Nacht schrei ich mein Krähenwort!"

Subway To Sally - Krähenkönig