Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class BallMovement : MonoBehaviour
- {
- private Vector3 startPosition;
- private Vector3 currentPosition;
- private float currTime;
- private float aTime;
- private bool hasPeeked;
- private bool hasMinPeek;
- private bool key;
- private Rigidbody body;
- [Range(0.0f, 5.0f)] public float speed = 0.1f;
- [Range(0.0f, 25.0f)] public float distance = 5.0f;
- // Start is called before the first frame update
- void Start()
- {
- body = GetComponent<Rigidbody>();
- startPosition = transform.position;
- currentPosition = startPosition;
- hasPeeked = false;
- hasMinPeek = false;
- }
- // Update is called once per frame
- void Update()
- {
- if (Input.GetMouseButton(0))
- key = true;
- if (key)
- {
- aTime = Time.deltaTime * 5.0f;
- if(transform.position.y >= 5.31f && !hasMinPeek)
- {
- transform.position = new Vector3(transform.position.x, transform.position.y - aTime, transform.position.z);
- currentPosition = transform.position;
- if (transform.position.y <= 5.31f)
- hasMinPeek = true;
- }
- else if (transform.position.y <= 8.73f && !hasPeeked)
- {
- transform.position = new Vector3(transform.position.x, transform.position.y + aTime, transform.position.z);
- currentPosition = transform.position;
- if (transform.position.y >= 8.73f)
- hasPeeked = true;
- }
- else if (hasPeeked)
- {
- // transform.position = new Vector3(transform.position.x, transform.position.y - aTime, transform.position.z);
- // currentPosition = transform.position;
- body.constraints = RigidbodyConstraints.None;
- }
- }
- if (!key)
- {
- currTime = Time.time;
- currentPosition = startPosition + new Vector3(Mathf.Sin(currTime * speed) * distance, 0.0f, 0.0f);
- transform.position = currentPosition;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement