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