Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Why is this not working?

Discussion in 'Input System' started by exploding_toaster, Aug 4, 2020.

  1. exploding_toaster

    exploding_toaster

    Joined:
    Jun 5, 2020
    Posts:
    46
    so i want make a mobile game (i don't know if ill actually turn it into one) but at the moment i just using mouse.position because me myself doesn't have a phone.
    when i put my cursor in the specified area it does absolutely nothing at all maybe its the wrong coords but it might be for some reason my player and the wall blocks have different coords so ill try that

    heres my code
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class playermovement : MonoBehaviour
    6. {
    7.     public float f;
    8.     public Rigidbody2D rb;
    9.     Vector2 x = new Vector2(100f , 0f);
    10.     Vector2 y = new Vector2(-100f, 0f);
    11.     // Update is called once per frame
    12.     void FixedUpdate()
    13.     {
    14.      
    15.         if (Input.mousePosition.x > 12.37 && Input.mousePosition.x < 8.28)
    16.             {
    17.             rb.AddForce(x); Debug.Log("itsworkingkinda");
    18.             }
    19.      
    20.     }
    note* theres no errors that i know of
    edit: its not wrong cords as long as i know but that isnt much
     
    Last edited: Aug 4, 2020