Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 richardzzzarnold · May 01, 2012 at 06:28 AM · transformarraybooleantarget

Accessing boolean properties from array of transforms

I am trying to make a script in which the characters( goats ) jump from spot to spot. I have an array of transforms which are jumpspots. The thing is that I only want them to jump to spots that are unoccupied so I am wondering how to do that. I have tried making another script for each transform with a boolean that indicates its state(full/empty). I want to make ScanForTarget function to only look for targets that are empty. I imagine that I need to make a new array ( one that has only empty spots )from the possibleTargets array but am not sure how to proceed.I could not work out how to check the possibleTargets boolean states. Also , how can I make to the (transform.LookAt(target);) move through a smooth rotation?it is instantaneous at present. Thanks.

 var front_switch : boolean;
 var customButton : GUIStyle;
 var possibleTargets : Transform[];
 var audioGoatObject : GameObject;
     
 var other : Rigidbody;
 var searchTag = "Respawn";
 var smoothTime = 0.3;
 private var velocity = Vector3.zero;
 // the frequency with which to re-scane for new nearest target in seconds 
 // (set in inspector)
 var scanFrequency = 1.0;
 
 // the current target
  var target : Transform;
 
 
 
 
 function Update() {
     // we rotate to look at the target every frame (if there is one)
 
     if (front_switch==false){
         transform.LookAt(target);
         var targetPosition : Vector3 = target.TransformPoint(Vector3(0, 0,0));
 other.useGravity = false;
 // Smoothly move the camera towards that target position
 transform.position = Vector3.SmoothDamp(transform.position, targetPosition,velocity, smoothTime);
 
     }
 }
 
 function ScanForTarget() {
     // this should be called less often, because it could be an expensive
     // process if there are lots of objects to check against
    target = possibleTargets[Random.Range(0, possibleTargets.length)].transform;
 
 }
 
 
 
 function OnGUI(){
  if(GUI.Button(Rect(50,Screen.height -150,Screen.width/10,Screen.width/10),"",customButton)) 
  {
  ScanForTarget();
 jump();
 audiojump();
 }
 }
 
 function jump(){ 
 
 animation.Play("jump");
 yield WaitForSeconds(1.5);
 animation.CrossFadeQueued("loop_goat");
 }
 
 function audiojump(){
 
 audioGoatObject.audio.enabled=true;
 yield WaitForSeconds(1);
 audioGoatObject.audio.enabled=false;
 }
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
Best Answer

Answer by chainedlupine · May 02, 2012 at 03:54 AM

There are many ways to skin this goat. (Ha! See what I did there?)

Is there a particular reason you are using an array of Transforms? I presume because these are actually GameObjects that exist in your Unity scene so they can be easily manipulated. If so, you can attach a component that contains the necessary bookkeeping information. So, create a script called JumpSpot and then assign it to the jump spot GameObjects. Then in your script, access it such as:

 target.GetComponent(JumpSpot).isAvailable = false

Or you could track the states in an array, as you mentioned.

Or you could, instead of storing GameObjects, store some specialized data structure -- a class that contained a Vector3 point plus a reference to whether the spot was open, or black or green or upside down or whatever else state information you wanted to store.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Boolean a Array of Transforms 1 Answer

have array target person of most priority/stick with top prior 0 Answers

What is wrong with this code? 0 Answers

transform.position not executed with OnTrigger2D 1 Answer

Get the number of false bools in GameObject[] (array) 3 Answers


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