Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
using UnityEngine;
using UnityEngine.EventSystems;
public class FixedButton : MonoBehaviour, IPointerUpHandler, IPointerDownHandler
{
[HideInInspector]
public bool Pressed;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
}
public void OnPointerDown(PointerEventData eventData)
{
Pressed = true;
}
public void OnPointerUp(PointerEventData eventData)
{
Pressed = false;
}
}
using UnityEngine;
using UnityEngine.EventSystems;
public class FixedTouchField : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
{
[HideInInspector]
public Vector2 TouchDist;
[HideInInspector]
public Vector2 PointerOld;
[HideInInspector]
protected int PointerId;
[HideInInspector]
public bool Pressed;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Pressed)
{
if (PointerId >= 0 && PointerId < Input.touches.Length)
{
TouchDist = Input.touches[PointerId].position - PointerOld;
PointerOld = Input.touches[PointerId].position;
}
else
{
TouchDist = new Vector2(Input.mousePosition.x, Input.mousePosition.y) - PointerOld;
PointerOld = Input.mousePosition;
}
}
else
{
TouchDist = new Vector2();
}
}
public void OnPointerDown(PointerEventData eventData)
{
Pressed = true;
PointerId = eventData.pointerId;
PointerOld = eventData.position;
}
public void OnPointerUp(PointerEventData eventData)
{
Pressed = false;
}
}
@hanuxieeee

This comment has been minimized.

Copy link

@hanuxieeee hanuxieeee commented Jul 17, 2018

not buttom jump

@jddfgfdfd

This comment has been minimized.

Copy link

@jddfgfdfd jddfgfdfd commented Oct 5, 2019

hi

@HonorsoftEntertainment

This comment has been minimized.

Copy link

@HonorsoftEntertainment HonorsoftEntertainment commented Jan 3, 2020

Your FixedButton script should be named "FixedButton.cs" not "Fixed Button.cs"

@aTasja

This comment has been minimized.

Copy link

@aTasja aTasja commented Jan 27, 2020

Thank you! It works!

@SubashKumarDodeja

This comment has been minimized.

Copy link

@SubashKumarDodeja SubashKumarDodeja commented Mar 5, 2020

player keeps moving in the same direction and the same speed until the player hits a wall and doesn’t respond to any other input on the joystick, and won’t stop even if I let go of the joystick.

@IraFaisal

This comment has been minimized.

Copy link

@IraFaisal IraFaisal commented Apr 27, 2020

When i import the joystick pack the fixedJoystick script did not have anything in it not even a single code can anyone of u plz send me that script ?

@aTasja

This comment has been minimized.

Copy link

@aTasja aTasja commented Apr 28, 2020

When i import the joystick pack the fixedJoystick script did not have anything in it not even a single code can anyone of u plz send me that script ?

You do not need this code. Watch the video carefully.

@ferdinandsp

This comment has been minimized.

Copy link

@ferdinandsp ferdinandsp commented Aug 5, 2020

Help
error CS1061: 'FixedJoystick' does not contain a definition for 'InputVector' and no accessible extension method 'InputVector' accepting a first argument of type 'FixedJoystick' could be found (are you missing a using directive or an assembly reference?)

@aTasja

This comment has been minimized.

Copy link

@aTasja aTasja commented Aug 5, 2020

Help
error CS1061: 'FixedJoystick' does not contain a definition for 'InputVector' and no accessible extension method 'InputVector' accepting a first argument of type 'FixedJoystick' could be found (are you missing a using directive or an assembly reference?)

FixedJoystick has Direction.

--Level.cs

void Update(){
//...
        var player = fps.GetComponent<PlayerMovement>();
        player.RunAxis = FixedJoistick.Direction;
//...
}
//...

--PlayerMovement.cs

public CharacterController controller;
..

public Vector2 RunAxis;
...
        void Update(){
        //...
        float x = RunAxis.x; 
        float z = RunAxis.y;

        Vector3 move = transform.right * x + transform.forward * z;
        controller.Move(move*speed*Time.deltaTime);

        velocity.y += gravity * Time.deltaTime;
        controller.Move(velocity * Time.deltaTime);   
//... 
}

Hope it will help.

@ferdinandsp

This comment has been minimized.

Copy link

@ferdinandsp ferdinandsp commented Aug 5, 2020

thanks u. its helpful :D

@Nayaniscool

This comment has been minimized.

Copy link

@Nayaniscool Nayaniscool commented Aug 10, 2020

hi

@Nayaniscool

This comment has been minimized.

Copy link

@Nayaniscool Nayaniscool commented Aug 10, 2020

it was helpful

@bedirhan07

This comment has been minimized.

Copy link

@bedirhan07 bedirhan07 commented Aug 12, 2020

@aTasja Help
Assets\Standard Assets\Characters\FirstPersonCharacter\Scripts\RigidbodyFirstPersonController.cs(149,9): error CS0103: The name 'controller' does not exist in the current context

@aTasja

This comment has been minimized.

Copy link

@aTasja aTasja commented Aug 12, 2020

@aTasja Help
Assets\Standard Assets\Characters\FirstPersonCharacter\Scripts\RigidbodyFirstPersonController.cs(149,9): error CS0103: The name 'controller' does not exist in the current context

I added a line about the controller in my code sample above.
CaracterController and PlayerMovement are components of the same gameObject.

@ditzel

This comment has been minimized.

Copy link
Owner Author

@ditzel ditzel commented Aug 12, 2020

Your FixedButton script should be named "FixedButton.cs" not "Fixed Button.cs"

done

@RoniPeve

This comment has been minimized.

Copy link

@RoniPeve RoniPeve commented Sep 14, 2020

Hello, I have a problem since I have other buttons on my canvas and when pressing them the camera moves to where I have pressed, I would like to know how to restrict certain touches
Español
hola, tengo un problema ya que tengo otros botones en mi canvas y al presionarlos la camara se mueve hacia donde he presionado, quisiera saber como restringir ciertos toques

@aTasja

This comment has been minimized.

Copy link

@aTasja aTasja commented Sep 14, 2020

Hello, I have a problem since I have other buttons on my canvas and when pressing them the camera moves to where I have pressed, I would like to know how to restrict certain touches
Español
hola, tengo un problema ya que tengo otros botones en mi canvas y al presionarlos la camara se mueve hacia donde he presionado, quisiera saber como restringir ciertos toques

Hi!
Panel and buttons should be separate objects of Canvas. Is your panel above buttons in the canvas's hierarchy?

@RoniPeve

This comment has been minimized.

Copy link

@RoniPeve RoniPeve commented Sep 14, 2020

@aTasja

This comment has been minimized.

Copy link

@aTasja aTasja commented Sep 15, 2020

@RoniPeve

above buttons in the canvas's hierarchy?

Yes:
-->Canvas
>Panel
>Button1
>Button2
......

The panel is before any button.

@RoniPeve

This comment has been minimized.

Copy link

@RoniPeve RoniPeve commented Sep 15, 2020

Yes, so I have it on my canvas.
I even reduced the panel so that it does not come into contact with the panel, but I still have the same problem
panel

@HonorsoftEntertainment

This comment has been minimized.

Copy link

@HonorsoftEntertainment HonorsoftEntertainment commented Sep 16, 2020

Hello, I have a problem since I have other buttons on my canvas and when pressing them the camera moves to where I have pressed, I would like to know how to restrict certain touches

-You have to use the UI "layers", located in the top right of the inspector. You can control which objects the touches affect. If you don't want an image to detect mouse clicks or touches, you have to uncheck "Raycast Target" in the object's Image Script (UI).
You can also set which objects block raycasting in the UI Canvas object (in the Inspector).

@RoniPeve

This comment has been minimized.

Copy link

@RoniPeve RoniPeve commented Sep 16, 2020

but if I deactivate "Raycast Target" the buttons will not work, what I want is that I can move the camera and be able to press the other buttons if the camera moves to the place where I pressed the buttons

@HonorsoftEntertainment

This comment has been minimized.

Copy link

@HonorsoftEntertainment HonorsoftEntertainment commented Sep 30, 2020

Deactivating the Raycast Target is so that object won't detect clicks, so you could enable or disable the raycast target checkbox from script when needed, however there is probably an easier way. You might want to make a 2 copies of your UI windows (the things you want to click?) then you can set the Raycast Target to ON on one, and OFF on the other, then you can easily enable the UI that has Raycast Target, and the other UI menu has Raycast Target off. Then when you switch, enable and disable the UI's so that the ones detecting raycasts are switched. I hope I am understanding your issue. Maybe if you can post a diagram or picture it will show us what you are trying to do.

@TeBidz

This comment has been minimized.

Copy link

@TeBidz TeBidz commented Oct 19, 2020

I get error like this (in MyScript of youtube) "The type or namespace name 'Joybutton' could not be found (are you missing a using directive or an assembly reference?)" what im wrong in here ↓↓↓
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MyScript : MonoBehaviour {

protected Joystick joystick;
protected Joybutton joybutton;

protected bool jump;

// use this for initialization
void Start () {
    joystick = FindObjectOfType<Joystick>();
    joybutton = FindObjectOfType<Joybutton>();
}

// Update is called once per frame
void Update() {

    var rigidbody = GetComponent<Rigidbody>();

    rigidbody.velocity = new Vector3(joystick.Horizontal * 100f,
                                     rigidbody.velocity.y,
                                     joystick.Vertical * 100f);
    
    if(!jump && joybutton.Pressed)
    {
        jump = true;
        rigidbody.velocity += Vector3.up * 100f;
    }

    if(jump && !joybutton.Pressed)
    {
        jump = false;
    }



}

}

@Piepop101

This comment has been minimized.

Copy link

@Piepop101 Piepop101 commented Oct 29, 2020

I got the script to work perfectly, but how do you get it to only single jump? Right now I can jump an infinite amount of times

@usamarao308

This comment has been minimized.

Copy link

@usamarao308 usamarao308 commented Dec 1, 2020

I got error "joyButton Does not contain defination for 'pressed'"

Capture

@usamarao308

This comment has been minimized.

Copy link

@usamarao308 usamarao308 commented Dec 1, 2020

please help

@Piepop101

This comment has been minimized.

Copy link

@Piepop101 Piepop101 commented Dec 1, 2020

@oleghwang

This comment has been minimized.

Copy link

@oleghwang oleghwang commented Dec 20, 2020

Please help me. I got error, NullReferenceException: Object reference not set to an instance of an object
OwnThirdPersonController.Update () (at Assets/OwnThirdPersonController.cs:40)
In fact my soldier doesn't have animation, it doesnt walk, just sliding , and touchfield and camera rotate slowly

`using UnityEngine;

public class OwnThirdPersonController : MonoBehaviour

{
public FixedJoystick LeftJoystick;
public FixedButton Button;
public FixedTouchField TouchField;

protected Actions Actions;
protected PlayerController PlayerController;
protected Rigidbody Rigidbody;

protected float CameraAngleY;
protected float CameraAngleSpeed = 0.1f;
protected float CameraPosY;
protected float CameraPosSpeed = 0.1f;

// Start is called before the first frame update
void Start()
{
    Actions = GetComponent<Actions>();
    PlayerController = GetComponent<PlayerController>();
    Rigidbody = GetComponent<Rigidbody>();

}

// Update is called once per frame
void Update()
{
    var input = new Vector3(LeftJoystick.input.x, 0, LeftJoystick.input.y);
    var vel = Quaternion.AngleAxis(CameraAngleY + 180, Vector3.up) * input * 5f;
    
    Rigidbody.velocity = new Vector3(vel.x, Rigidbody.velocity.y, vel.z);
    transform.rotation = Quaternion.AngleAxis(CameraAngleY + 180 + Vector3.SignedAngle(Vector3.forward, input.normalized + Vector3.forward * 0.001f, Vector3.up), Vector3.up);

    CameraAngleY += TouchField.TouchDist.x * CameraAngleSpeed;
   
    Camera.main.transform.position = transform.position + Quaternion.AngleAxis(CameraAngleY, Vector3.up) * new Vector3(0, 3, 4);
    Camera.main.transform.rotation = Quaternion.LookRotation(transform.position + Vector3.up * 2f - Camera.main.transform.position, Vector3.up);

    if (Rigidbody.velocity.magnitude > 3f)
        Actions.Run();
    else if (Rigidbody.velocity.magnitude > 0.5f)
        Actions.Walk();
    else
        Actions.Stay();
}   

}`

@cyberjj999

This comment has been minimized.

Copy link

@cyberjj999 cyberjj999 commented Jan 5, 2021

Hi guys, how can I make the camera rotate up and down instead of just sideway as shown in the video?

@SebaBLanes

This comment has been minimized.

Copy link

@SebaBLanes SebaBLanes commented Jan 17, 2021

Help
error CS1061: 'FixedJoystick' does not contain a definition for 'InputVector' and no accessible extension method 'InputVector' accepting a first argument of type 'FixedJoystick' could be found (are you missing a using directive or an assembly reference?)

FixedJoystick has Direction.

--Level.cs

void Update(){
//...
var player = fps.GetComponent();
player.RunAxis = FixedJoistick.Direction;
//...
}
//...
--PlayerMovement.cs

public CharacterController controller;
..

public Vector2 RunAxis;
...
void Update(){
//...
float x = RunAxis.x;
float z = RunAxis.y;

    Vector3 move = transform.right * x + transform.forward * z;
    controller.Move(move*speed*Time.deltaTime);

    velocity.y += gravity * Time.deltaTime;
    controller.Move(velocity * Time.deltaTime);   

//...
}
Hope it will help.


Hi, I'm a student and I have the same 'InputVector' error ... I thank "aTasja" for a little more detailed help.
Thanks and greetings from Uruguay.

@anizmamos

This comment has been minimized.

Copy link

@anizmamos anizmamos commented Feb 12, 2021

error CS1061: 'FixedJoystick' does not contain a definition for 'InputVector' and no accessible extension method 'InputVector' accepting a first argument of type 'FixedJoystick' could be found (are you missing a using directive or an assembly reference?)

I saw some answers here but i still cant fix this error!
Can someone help me?

@JoBobNenner

This comment has been minimized.

Copy link

@JoBobNenner JoBobNenner commented Feb 13, 2021

error CS1061: 'FixedJoystick' does not contain a definition for 'InputVector' and no accessible extension method 'InputVector' accepting a first argument of type 'FixedJoystick' could be found (are you missing a using directive or an assembly reference?)

I saw some answers here but i still cant fix this error!
Can someone help me?

Having this error too

@Harsh3736

This comment has been minimized.

Copy link

@Harsh3736 Harsh3736 commented Apr 20, 2021

Will You Help Plz Plz.Plz
16189283175937974647288333940034

Please Help Me Please

@zeekee

This comment has been minimized.

Copy link

@zeekee zeekee commented Apr 23, 2021

MoveJoystick.inputVector is equals to MoveJoystick.Direction

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment