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 /
This question was closed May 07, 2018 at 08:13 AM by Myth for the following reason:

The question is answered, right answer was accepted

avatar image
1
Question by Myth · Feb 09, 2011 at 03:11 AM · cameracontrolswitchturretswitch characters

View and control script broken?

Hi all,

I have created this script to change between "seats" on a space craft. I had it working with just one "seat" (and its camera), and now after expanding the script to accommodate the other "seats" it no longer works for even the first seat.

Any pointers are greatly appreciated.

// seat position var driver_seat : Transform; var seat_1 : Transform; var seat_2 : Transform; var seat_3 : Transform; var seat_4 : Transform; var seat_5 : Transform; var seat_6 : Transform;

// turret and ship cams var ship_cam : Camera; var cam1 : Camera; var cam2 : Camera; var cam3 : Camera; var cam4 : Camera; var cam5 : Camera; var cam6 : Camera;

// timer var timer : int = 30;

// ship var ship : GameObject;

// active control vars var state : int = -1;

// player position & cam var play : Transform; var player_cam : Camera; function Update () { if ( Input.GetAxis ("e_key") && state == -1 && timer < 0) { timer = 30;

     if(Vector3.Distance (driver_seat.position, play.position ) &lt; 1.5 )
     {
         state = 0;
         ship.BroadcastMessage ("Activate_Turret", 0);
     }

     //
     if(Vector3.Distance (seat_1.position, play.position ) &lt; 3 )
     {
         state = 1;
         ship.BroadcastMessage ("Activate_Turret", 1);
         print ("a");
     }

     //
     if(Vector3.Distance (seat_2.position, play.position ) &lt; 1.5 )
     {
         state = 2;
         ship.BroadcastMessage ("Activate_Turret", 2);
     }

     //
     if(Vector3.Distance (seat_3.position, play.position ) &lt; 1.5 )
     {
         state = 3;
         ship.BroadcastMessage ("Activate_Turret", 3);
     }

     //
     if(Vector3.Distance (seat_4.position, play.position ) &lt; 1.5 )
     {
         state = 4;
         ship.BroadcastMessage ("Activate_Turret", 4);
     }

     //
     if(Vector3.Distance (seat_5.position, play.position ) &lt; 1.5 )
     {
         state = 5;
         ship.BroadcastMessage ("Activate_Turret", 5);
     }

     //
     if(Vector3.Distance (seat_6.position, play.position ) &lt; 1.5 )
     {
         state = 6;
         ship.BroadcastMessage ("Activate_Turret", 6);
     }
 }

 // get out of turrets
 if ( Input.GetAxis ("e_key") &amp;&amp; state &gt; -1 &amp;&amp; timer &lt; 0)
 {
     state = -1;
     timer = 30;
     BroadcastMessage ("Activate_Turret", -1);
 }


 // switch cameras
 // player cam
 if (state == -1)
 {
     player_cam.GetComponent("Camera").active = true;
 }
 else
 {
     player_cam.GetComponent("Camera").active = false;
 }

 // cam 0
 if (ship_cam != null) 
 {
     if (state == 0)
     {
         ship_cam.GetComponent("Camera").active = true;
     }
     else
     {
         ship_cam.GetComponent("Camera").active = false;
     }
 }

 //cam 1
 if (state == 1)
 {
     cam1.GetComponent("Camera").active = true;
 }
 else
 {
     cam1.GetComponent("Camera").active = false;
 }

 // cam 2
 if (state == 2)
 {
     cam2.GetComponent("Camera").active = true;
 }
 else
 {
     cam2.GetComponent("Camera").active = true;
 }

 // cam 3
 if (state == 3)
 {
     cam3.GetComponent("Camera").active = true;
 }
 else
 {
     cam3.GetComponent("Camera").active = true;
 }

 // cam 4
 if (state == 4)
 {
     cam4.GetComponent("Camera").active = true;
 }
 else
 {
     cam4.GetComponent("Camera").active = true;
 }

 // cam 5
 if (state == 5)
 {
     cam5.GetComponent("Camera").active = true;
 }
 else
 {
     cam5.GetComponent("Camera").active = true;
 }

 // cam 6
 if (state == 6)
 {
     cam6.GetComponent("Camera").active = true;
 }
 else
 {
     cam6.GetComponent("Camera").active = true;
 }

}

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

  • Sort: 
avatar image
3
Best Answer

Answer by Bunny83 · Feb 09, 2011 at 03:41 AM

I think you forgot to decrease your timer. And a copy&past error :D

Almost all cameras get set to "true" in both pathes. I think you want to turn them off in the else block ;)

And just a hint: why don't us use an array for your seats and cams? That script hurts inside :D
good luck.

Comment
Add comment · Show 2 · 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
avatar image Myth · Feb 09, 2011 at 06:40 AM 0
Share

As of yet I have been unable to figure out how to use arrays in unity - I used to use dark basic and life was so much simpler!

avatar image Jesse Anders · Feb 09, 2011 at 08:50 AM 1
Share

If you're having trouble with arrays, post here or on the forums and someone will be able to help. (Aside from a few UnityScript quirks, working with arrays is the same in Unity as anywhere else, so there's really no point in trying to work around them.)

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

How to make camera position relative to a specific target. 1 Answer

character switching on collision 1 Answer

changing player (getting in vehicles) 3 Answers

How to set main camera? 3 Answers

Swapping Cameras Disables Keyboard Input 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