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 jhonaeroxsanchez · Dec 06, 2018 at 06:34 AM · scripting problem

Need little help with my Script i want to Add Min Height and Maxheight in ButtonScript

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.SceneManagement;
 using UnityEngine.UI;
  
 public class Player : MonoBehaviour {
  
     private Vector2 targetPos;
     public float Yincrement;
  
     public float speed;
     public float maxHeight;
     public float minHeight;
  
     public int health = 3;
  
     public GameObject effect;
     public Animator camAnim;
     public Text healthDisplay;
     public GameObject character;
  
     private Rigidbody2D characterBody;
  
     public GameObject gameOver;
     public GameObject popSound;
  
     private void Update()
     {
  
  
             healthDisplay.text = health.ToString ();
  
             if (health <= 0) {
                 gameOver.SetActive (true);
                 Destroy (gameObject);
             }
            
             transform.position = Vector2.MoveTowards (transform.position, targetPos, speed * Time.deltaTime);
  
             if (Input.GetKeyDown (KeyCode.UpArrow) && transform.position.y < maxHeight) {
                 Instantiate (popSound, transform.position, Quaternion.identity);
                 camAnim.SetTrigger ("shake");
                 Instantiate (effect, transform.position, Quaternion.identity);
                 targetPos = new Vector2 (transform.position.x, transform.position.y + Yincrement);
  
             } else if (Input.GetKeyDown (KeyCode.DownArrow) && transform.position.y > minHeight) {
                 Instantiate (popSound, transform.position, Quaternion.identity);
                 camAnim.SetTrigger ("shake");
                 Instantiate (effect, transform.position, Quaternion.identity);
                 targetPos = new Vector2 (transform.position.x, transform.position.y - Yincrement);
  
             }
         }
  
     public void BtnUp()
     {
         transform.position += Vector3.up;
         Instantiate (popSound, transform.position, Quaternion.identity);
         camAnim.SetTrigger ("shake");
         Instantiate (effect, transform.position, Quaternion.identity);
         targetPos = new Vector2 (transform.position.x, transform.position.y + Yincrement);
     }
  
     public void BtnDown()
     {
         transform.position -= Vector3.up;
         Instantiate (popSound, transform.position, Quaternion.identity);
         camAnim.SetTrigger ("shake");
         Instantiate (effect, transform.position, Quaternion.identity);
         targetPos = new Vector2 (transform.position.x, transform.position.y - Yincrement);
     }
 }


Guys any one know how will i put the right code in my BtnUp and BtnDown script because i want to add more function like i want BtnUp and BtnDown to have limit in clicking like he will just Go up in 2-3 times and Down with a limit of 2-3 times to Down so i wont flew through the scene :D little bit confused on how ill put the right code for it ive tried and read lots of codes and i cant find similar with my problem and i cant find the right code pleasee help thankyou newbie only :D and doing my first game hehehe thankyou guys HELP :D

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

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

168 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Occlusion Culling with the OVRCameraRig (Oculus Rift)? 0 Answers

"Can't add script behaviour VisualContainerAsset. The script needs to derive from MonoBehaviour" - from 2d rouglike tutorial 1 Answer

Changing animation duration 0 Answers

how do I fixate a position through script. 1 Answer

Making a gameobject inactive and locating a clone. What's wrong with the script? 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