Skip to content

Instantly share code, notes, and snippets.

@ditzel
Last active March 14, 2024 18:25
Show Gist options
  • Star 44 You must be signed in to star a gist
  • Fork 17 You must be signed in to fork a gist
  • Save ditzel/0257d74a7a04626efce7bd1f7a6cfaa0 to your computer and use it in GitHub Desktop.
Save ditzel/0257d74a7a04626efce7bd1f7a6cfaa0 to your computer and use it in GitHub Desktop.
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;
}
}
@usamarao308
Copy link

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

Capture

@usamarao308
Copy link

please help

@Piepop101
Copy link

Piepop101 commented Dec 1, 2020 via email

@oleghwang
Copy link

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
Copy link

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

@SebaBLanes
Copy link

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
Copy link

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?

@dustinh8080
Copy link

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
Copy link

Will You Help Plz Plz.Plz
16189283175937974647288333940034

Please Help Me Please

@zeekee
Copy link

zeekee commented Apr 23, 2021

MoveJoystick.inputVector is equals to MoveJoystick.Direction

@Adnan2805
Copy link

i dont find FuxedJoystick srcipt please some one can send me

Copy link

ghost commented Feb 4, 2023

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?)

CS1061 'object' does not contain a definition for 'x' and no accessible extension method 'x' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)please help me in this anyone?

Copy link

ghost commented Feb 4, 2023

Error CS0029 Cannot implicitly convert type 'UnityEngine.Quaternion' to 'UnityEngine.Vector3'

also this error is come to distrub me please help me solve this ?

Copy link

ghost commented Feb 4, 2023

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

Copy link

ghost commented Feb 4, 2023

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.

Can please tell me in which componet this both file is put or tell can i create this two file

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