• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Alasdair · Mar 06, 2010 at 08:46 PM · classesstats

Controlling One of Several Similar Playing Pieces

hello, I'm trying to create a little tactical squad shooter where you control your squad one man at a time.

Story so far: I've made a prefab for the basic squad member.

I've made a Controller script which is attached to the Main Camera. It finds all the team members (using tags) and when I right click, the camera moves to the next squad members position and activates the mouselook and FPSWalker components.. so this allows you to control each team member one at a time.

The Problem: I'm now wanting to introduce some more complicated behaviour, such as, set a limit on how long each piece can be controlled for. So I've added a script to each SquadMember GameObject which contains:

static var MoveTime : int; var moveTime : int;

function Start () { MoveTime = moveTime; }

function Update () { }

So then using the Unity interface, I've set one Squad member's moveTime to 3 seconds, and one to 6 seconds. The Controller script is then meant to read this information and use it to control how long each man can be moved for:

// get all playing pieces in a gameobject array friendlyPieces = GameObject.FindGameObjectsWithTag("RedPlayer");

/... some code I've missed out which updates activePiece when I click the mouse... /

currentPiece = friendlyPieces[activePiece]; // move camera transform.position = currentPiece.transform.position; transform.rotation = currentPiece.transform.rotation; transform.parent = currentPiece.transform; // enable player control currentPiece.GetComponent(MouseLook).enabled = true; currentPiece.GetComponent(FPSWalker).enabled = true; currentPieceMoveTime = currentPiece.GetComponent(PlayerStats).MoveTime

However, this doesn't seem to work. Although the camere correctly moves to a new tagged GameObject when I update activePiece, it always reports the same currentPieceMoveTime.

Any suggestions? Am I right in thinking I need to learn how to use classes??

Thanks

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by qJake · Mar 22, 2010 at 09:23 PM

Did you count down your moveTime when the piece is active?

This isn't line-for-line code with your script, but you'd want to do something like this:


function Update()
{
     if(isActivePiece)
     {
          // Subtracts time in seconds. deltaTime is (float) time
          // in seconds since last Update() call.
          moveTime -= Time.deltaTime;
     }
}

It doesn't look like you have the "isActivePiece" bool, so you'll need to create that yourself.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

How to differentiate between players in multiplayer game 1 Answer

How to make classes? 2 Answers

Difficulty instantiating to a custom class 2 Answers

Organizing variables in the inspector 5 Answers

Class function not working (uniscript) 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges