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 BulletBehaviourScript : MonoBehaviour
- {
- public Vector2 deltaPosition;
- public GameObject sphere;
- public Vector3 startMousePosition;
- //Declare a variable to store hit data
- private RaycastHit hit;
- private bool activation = true;
- public float xForceMultiplier = 0.5f;
- #region Unity Messages
- // Function thats called each frame
- private void Update()
- {
- //If user pressed left mouse button
- if (Input.GetMouseButtonDown(0))
- {
- //Launch raycast from mouse position and save the data to variable
- if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit))
- {
- // IF object has proper tag
- if (hit.transform.CompareTag("Interactable"))
- {
- //Set start mouse position and show information
- Debug.Log("Elo mordy");
- startMousePosition = Input.mousePosition;
- }
- }
- }
- //If user is pressing left mouse button , update sphere position, corresponding to mouse position
- if (Input.GetMouseButton(0))
- {
- sphere.transform.position = (Input.mousePosition - startMousePosition) / 50;
- }
- //If user lets go of mouse button, calculate force and launch sphere
- if (Input.GetMouseButtonUp(0) )
- {
- deltaPosition = Input.mousePosition - startMousePosition;
- sphere.GetComponent<Rigidbody>().isKinematic = false;
- sphere.GetComponent<Rigidbody>().AddForce(new Vector3(-deltaPosition.x * xForceMultiplier, 2, 2) * 300);
- }
- }
- #endregion
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement