Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

How to make game play slower when dragging and shooting

Discussion in 'Scripting' started by ScottGameDevelopment, Aug 14, 2020.

  1. ScottGameDevelopment

    ScottGameDevelopment

    Joined:
    Apr 7, 2020
    Posts:
    42
    Hello everyone im having trouble with the gameplay i have the script working but when you drag to shoot player forwards its too fast and i was wandering how to slow down the gameplay when dragging and shooting here's my script. thx

    using UnityEngine;

    public class ShootBall : MonoBehaviour
    {
    private LineRenderer _lineRenderer;
    public void Start()
    {
    _lineRenderer = gameObject.AddComponent<LineRenderer>();
    _lineRenderer.SetWidth(0.2f, 0.2f);
    _lineRenderer.enabled = false;
    }

    private Vector3 _initialPosition;
    private Vector3 _currentPosition;
    public void Update()
    {
    if (Input.GetMouseButtonDown(0))
    {
    _initialPosition = GetCurrentMousePosition().GetValueOrDefault();
    _lineRenderer.SetPosition(0, _initialPosition);
    _lineRenderer.SetVertexCount(1);
    _lineRenderer.enabled = true;
    }
    else if (Input.GetMouseButton(0))
    {
    _currentPosition = GetCurrentMousePosition().GetValueOrDefault();
    _lineRenderer.SetVertexCount(2);
    _lineRenderer.SetPosition(1, _currentPosition);

    }
    else if (Input.GetMouseButtonUp(0))
    {
    _lineRenderer.enabled = false;
    var releasePosition = GetCurrentMousePosition().GetValueOrDefault();
    var direction = releasePosition - _initialPosition;
    Debug.Log("Process direction " + direction);
    }
    }

    private Vector3? GetCurrentMousePosition()
    {
    var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    var plane = new Plane(Vector3.forward, Vector3.zero);

    float rayDistance;
    if (plane.Raycast(ray, out rayDistance))
    {
    return ray.GetPoint(rayDistance);

    }

    return null;
    }

    }
     
    Last edited: Aug 14, 2020
  2. mgrekt

    mgrekt

    Joined:
    Jun 22, 2019
    Posts:
    92
    https://forum.unity.com/threads/using-code-tags-properly.143875/ Use code tags thanks.
     
    eses likes this.
  3. copseyi

    copseyi

    Joined:
    Jun 22, 2020
    Posts:
    8
    It's nice to see that mgrekt will just say to use code tags and then don't contribute to helping the solution. Though yes, you should use code tags and could work on your spelling and grammar. Either way, Time.timeScale should affect the way time works in your game. Instead of using it the way they are, add it into a few of your if statements to where you want the time to be slowed. You can find a previous forum article here: https://forum.unity.com/threads/slowing-down-time.60715/ and will find the Unity document here: https://docs.unity3d.com/ScriptRefe...13.1457496571.1597349415-602321558.1589329760