Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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.

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

Editting a custom javascript class in the inspector 1 Answer

Using AddComponent to add a Sub Class using a String 4 Answers

Where is the best place to host a class that is not intended to be a MonoBehaviour or Component? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges