Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.EventSystems;
- using UnityEngine.UI;
- using TMPro;
- public class PlayerTargeting : MonoBehaviour {
- // Projectile Stuff
- private float ballForce;
- private float finalForce;
- public float forceMultiplier = 1.0f;
- public Transform ballSpawn;
- public Rigidbody ball;
- GameObject prefab;
- public GameObject discoBall;
- // Raycast Stuff
- // Targeting Stuff for UI Crosshair
- public GameObject cursor; //crosshair
- public Canvas canvas; //parent canvas for crosshair
- float pixelX; //possible deprecated
- float pixelY;
- Vector2 cursorPos;
- public float posX;
- public float posY;
- // UI Stuff
- public TextMeshProUGUI scouter;
- private bool isDown;
- private bool charging = true;
- private bool draining = false;
- // Joystick
- private Vector3 rightJoystickInput;
- public float cursorMoveSpeed = 150f;
- public bool flipY = false;
- public bool flipX = false;
- // Use this for initialization
- void Start()
- {
- }
- // Update is called once per frame
- void Update()
- {
- // RightJoyStick - Move UI Crosshair
- rightJoystickInput = RightJoystick.Instance.GetInputDirection();
- float xMovementRightJoystick = rightJoystickInput.x; // The horizontal movement from joystick 02
- float yMovementRightJoystick = rightJoystickInput.y; // The vertical movement from joystick 02
- float inputX = xMovementRightJoystick * (flipX ? -1 : 1);
- float inputY = yMovementRightJoystick * (flipY ? -1 : 1);
- float deltaX = inputX * cursorMoveSpeed;
- float deltaY = inputY * cursorMoveSpeed;
- cursorPos.x += deltaX * Time.deltaTime;
- cursorPos.y += deltaY * Time.deltaTime;
- if( cursorPos.x < 0 ) cursorPos.x = 0;
- if( cursorPos.x > Screen.width ) cursorPos.x = Screen.width;
- if( cursorPos.y < 0 ) cursorPos.y = 0;
- if( cursorPos.y > Screen.height ) cursorPos.y = Screen.height;
- cursor.transform.position = cursorPos;
- // Raycast Stuff
- Ray ray = Camera.main.ScreenPointToRay( cursorPos );
- RaycastHit hit;
- Debug.DrawRay(ray.origin, ray.direction * 100, Color.yellow);
- if (Physics.Raycast(transform.position, -Vector3.up, out hit))
- {
- print("Found an object - distance: " + hit.distance);
- }
- // Firing Mechanism - Power Calculations
- if (FireButton.Instance.isDown)
- {
- if (charging)
- {
- ballForce += 1f;
- if (ballForce >= 100f)
- {
- ballForce = 100f;
- charging = false;
- draining = true;
- }
- }
- if (draining)
- {
- ballForce -= 0.7f;
- if (ballForce <= 0f)
- {
- ballForce = 0f;
- draining = false;
- charging = true;
- }
- }
- // Debugging ballForce
- print(ballForce);
- // Need to change this to a graphical power bar
- int powerlvl = (int)ballForce;
- scouter.text = "Power: " + powerlvl.ToString();
- }
- if (FireButton.Instance.isDown == false)
- {
- if (ballForce > 0f)
- {
- if (ballForce >= 10f)
- {
- finalForce = 30000f;
- }
- if (ballForce <= 11f && ballForce >= 20f)
- {
- finalForce = 35000f;
- }
- if (ballForce <= 21f && ballForce >= 30f)
- {
- finalForce = 40000f;
- }
- if (ballForce <= 31f && ballForce >= 40f)
- {
- finalForce = 50000f;
- }
- if (ballForce <= 41f && ballForce >= 50f)
- {
- finalForce = 60000f;
- }
- if (ballForce <= 51f && ballForce >= 60f)
- {
- finalForce = 70000f;
- }
- if (ballForce <= 61f && ballForce >= 70f)
- {
- finalForce = 80000f;
- }
- if (ballForce <= 71f && ballForce >= 80f)
- {
- finalForce = 90000f;
- }
- if (ballForce <= 81f && ballForce >= 90f)
- {
- finalForce = 100000f;
- }
- if (ballForce <= 91f && ballForce >= 95f)
- {
- finalForce = 150000f;
- }
- if (ballForce <= 96f && ballForce >= 97f)
- {
- finalForce = 200000f;
- }
- if (ballForce <= 98f && ballForce >= 99f)
- {
- finalForce = 300000f;
- }
- if (ballForce == 100f)
- {
- finalForce = 400000f;
- }
- // Launch Ball
- Rigidbody ballRigidbody;
- // Ball Spawns at Camera presently.
- ballRigidbody = Instantiate(ball, ballSpawn.position, ballSpawn.rotation) as Rigidbody;
- ballRigidbody.AddForce(ray.direction * finalForce * forceMultiplier);
- // Actually getting the ball to align to face raytrace direction to fire on target.
- ballForce = 0f;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement