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 MISIKE · Mar 19, 2013 at 02:26 AM ·

Do I overcomplicate something in this code?

I would like to attain it by the cube being an object only,let him jump then when I ovecome it W button. When I keep it pushed though W button,let the cube not be hopping though continuously then.

 using UnityEngine;
 using System.Collections;
 
 public class CubePlayerJumpScript : MonoBehaviour {
     
     private float jumpSpeed = 1100f; //moveSpeed = 5f;
     private bool heClashed = false;
     
     // Use this for initialization
     void Start()
     {
         Physics.gravity = new Vector3(0, -70, 0);
     }
     
     // Update is called once per frame
     void Update()
     {
     }
     
     void OnCollisionEnter(Collision theCollision)
     {
         if(theCollision.gameObject.name == "Cube Soil")
         {
             heClashed = true;
             rigidbody.constraints = RigidbodyConstraints.FreezePositionZ | RigidbodyConstraints.FreezeRotation;
         }
     }
     
     void OnGUI()
     {
         Event e = Event.current;
         if(e.isKey)
             switch(e.keyCode)
             {
                 case KeyCode.W:
                 {
                     if(heClashed && Input.GetKeyDown(e.keyCode))
                     {
                         rigidbody.constraints = RigidbodyConstraints.FreezePositionX | RigidbodyConstraints.FreezePositionZ | RigidbodyConstraints.FreezeRotation;
                         rigidbody.AddForce(Vector3.up * jumpSpeed);
                         heClashed = false;
                     }
                     break;
                 }
                 default:
                     break;
             }
     }
     
 
 }
 
Comment
Add comment · Show 1
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 MISIKE · Mar 19, 2013 at 02:32 AM 0
Share

$$anonymous$$y question it,that overcomplicate this something and,how I shall solve the task by the usage of switch how so,how the switch should not be needed-et unnecessary one to do with this condition exa$$anonymous$$ation: Input.Get$$anonymous$$eyDown(e.keyCode)

I want to solve it by the usage of switch so,that if I keep it pressed W let my finger not be jumping then s$$anonymous$$dily the cube object.

The code what you see here it works perfectly only I have trouble with him,that the switch becomes unnecessary because of the condition exa$$anonymous$$ation in him.

But I would like to use it anyway the switch. Namely because of that because there will be many buttons then that down tooth to need to shake hands and 20 or 30 would not like it to write a condition exa$$anonymous$$ation.

0 Replies

· Add your reply
  • Sort: 

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

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

A node in a childnode? 1 Answer

Prevent colliders intersecting. 1 Answer

How to make an instantiated enemy to translate to a point first and then to lookAt the player ??? 2 Answers

Can I use Unity to create a Facebook Game? 1 Answer

Object Reference Not Set As Instance error from ngui code 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