- Home /
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
Your answer
