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 Naszia · Sep 27, 2011 at 10:21 AM · gameplatformer

Platformer object control

I have a platformer game that has a bunch of red and blue cubes. and i need a way/script so that everytime i press say alt, either the red or the blue cubes come into play. so basically on alt they would shift back and forth into line of play. THanks.

Comment
Add comment · Show 6
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 timsk · Sep 27, 2011 at 10:58 AM 0
Share

By "come into play" do you mean the cube then becomes the players controllable character?

Are you trying to switch the players controllable character between the red and blue cubes on the press of a key?

avatar image Naszia · Sep 27, 2011 at 11:01 AM 0
Share

Sorry should have been more clear. erm. you dont play as the cubes but i want them to be platforms that when i press alt either hte red or the blue ones come into the same line as the player and you can jump on them. when the red ones are able to be used the other ones will go back into the background a little. it only needs to move the red and blue cubes back and forth on a touch of a button.

avatar image timsk · Sep 27, 2011 at 11:05 AM 0
Share

. _

. .

. .

_ .

Like so? "_" is a cube "." is movement.

So you press Alt once, the red cube comes forward, press it again and the red goes back and the blue comes forward?

avatar image Naszia · Sep 27, 2011 at 11:10 AM 0
Share

i clearly suck at explaining things ahah. But yeah you got the idea.:)

avatar image timsk · Sep 27, 2011 at 11:16 AM 0
Share

Well there are 2 ways i can think to do this:

  1. iTween (by far the easiest)

  2. using an animation thats played "Input.On$$anonymous$$eyDown"

Do you use iTween?

I will do my best to point you in the right direction if not.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by timsk · Sep 27, 2011 at 12:06 PM

I highly suggest iTween, makes any kind of movement so easy (i also suggest the iTween visual editor, reduces the amount of coding needed):

http://itween.pixelplacement.com

http://dkoontz.wordpress.com/itween-visual-editor/

if using iTween, you can use this code to move the platform:

 function MovePlatforms()
 if(Input.GetButton ("definekey")
 {
 iTween.MoveAdd(gameObject,Vector3(5,0,0),2)
 }

Like i said, its easier with the visual editor.

If you don't want to use iTween. You can create an animation where 1 cube moves forward and the other back and then use this:

 function MovePlatforms()
 if(Input.GetButton ("definekey")
 {
 Animation.play("moveplatforms");
 }
 //you can use Animation.Rewind("moveplatforms"); or animation["moveplatforms"].speed = -1.0;to play animations backwards

Heres some references to help you:

http://unity3d.com/support/documentation/ScriptReference/Animation.html

http://unity3d.com/support/documentation/ScriptReference/WrapMode.html (ClampForever should work for this)

http://unity3d.com/support/documentation/ScriptReference/AnimationState.html

Good luck! :)

Comment
Add comment · Show 11 · 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 Naszia · Sep 27, 2011 at 12:24 PM 0
Share

Your awesome. Thanks heaps ^^

avatar image timsk · Sep 27, 2011 at 12:26 PM 0
Share

made me feel all fuzzy inside ^^.

Just another note. Look into switch...case statements, if you had more than 2 cubes, you would probably need to use one of those. I'm not great with them, so cant really help you.

Hope your games goes well!

avatar image Naszia · Sep 27, 2011 at 01:06 PM 0
Share

Is there a reason why its saying unknown identifier 'iTween' its in the same folder it should be picking it up :/

avatar image timsk · Sep 27, 2011 at 01:10 PM 0
Share

make sure the iTween files are located in the "Plugins" folder in your project.

avatar image Naszia · Sep 27, 2011 at 01:29 PM 0
Share

ahah all fuzzy is good :P and i dont seem to have a plugins folder. Just make one? and i found out that my itween file is in c# is that ok if its being sorced through a javascript?

Show more comments

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

What's Tight Gameplay? 1 Answer

getting udp package info inside unity (GlovePIE) 0 Answers

How can I change rotation of spawning platforms?(platforms must appear at angles of -45 degrees Y),How can change rotation of platforms? (plantforms must appear at angles of -45 degrees Y) 1 Answer

2D 360 degress platformer example needed 0 Answers

Unity 2d Freezing Player in Position on Collision 4 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