Search Unity

lessons wanted on how to debug

Discussion in 'Getting Started' started by Smitty3264, Oct 27, 2020.

  1. Smitty3264

    Smitty3264

    Joined:
    Sep 12, 2020
    Posts:
    38
    hello all. I am working on this script for a pool game. I'm trying to set target position to mouse click and then hit ui button to send cue ball towards target position. problem is bool is enabled when I click mouse button not the ui button and I am not sure what the target position is being set to but its not the mouse position I intended.
    just need to now how to get the target position in the console view or draw a line to it or whatever I need to do to find out where I am sending the ball.

    Code (CSharp):
    1. public class aim : MonoBehaviour
    2. {
    3.  
    4.     public Rigidbody rb;
    5.     public bool strikeBall;
    6.     private Vector3 targetPos;
    7.    
    8.  
    9.     void start()
    10.     {
    11.         rb = GetComponent<Rigidbody>();
    12.         strikeBall = false;
    13.     }
    14.  
    15.     void FixedUpdate()
    16.     {
    17.         var mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
    18.         var mouseDir = mousePos;
    19.         mouseDir.z = 0.0f;
    20.         mouseDir = mouseDir.normalized;
    21.  
    22.  
    23.         if (Input.GetMouseButtonDown(0))
    24.         {
    25.             targetPos = mousePos;
    26.         }
    27.         if (strikeBall)
    28.         {
    29.  
    30.             rb.AddForce(targetPos, ForceMode.Impulse);
    31.         }
    32.     }
    33. }
    any input is appreciated.
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859