Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

AI, Attributes, and Script lifetime

Discussion in 'Editor & General Support' started by hsparra, Jul 18, 2005.

  1. hsparra

    hsparra

    Joined:
    Jul 12, 2005
    Posts:
    750
    I have the following 3 question reguarding the prefered method to use in Unity:

    1) What is the preferred way to handle AI type logic? Is it to attach and AI script to an object? To call an AI script from a script attached to an object?

    2) How to you track attributes, say ammo for a weapons, fuel, and the like?

    3) What is the lifetime of a script attached to an object? Is it for the life of the object? If so, I assume the variables are maintained for the life of the object depending on the scope of the script being used.
     
  2. freyr

    freyr

    Joined:
    Apr 7, 2005
    Posts:
    1,148
    This is how I would implement it. Of course the more experienced game coders at OTEE could chime in with some details, and corrections....

    Ad 1: The preferred way is to add small behaviour scripts attached to the individual objects. Possibly under control from a central script attached to a game manager object (An empty game object containing only script behaviours.)

    Ad 2: This would go into the game manager script. Note that the objects in the first scene in a published game survive when the next level is loaded, so if the game manager is in the first scene, everything inside will survive for the entire game.

    Ad 3: You are correct. The lifetime from object creation until the object is destroyed. A script can also be attached to and detached from an object from other script code. As before, objects that are loaded with the first scene in a game are not destroyed when loading a new level. ... also if the object is saved inside a scene or a prefab, all script variables are saved with it.
     
  3. hsparra

    hsparra

    Joined:
    Jul 12, 2005
    Posts:
    750
    freyr, thank you for the response. I will have to play some this evening to see what other questions this may create :)