For the error, you’ll likely want to check that GetTouch(0) is a valid reference. Where in the code when you step through it by hand, do you expect the jumping to stop? As mentioned, Touchphase.Began may only happen once.
Visual Studio’s console say is a valid reference but Unity’s console say it’s not valid so I don’t know why the GetTouch(0) is not valid. Can I’ve help for than I can understand?
For stopping jump, I’m want help too!
Sorry if I ask a lot of questions, I’m new in the Unity Universe!
Because you’re asking it what the phase of the touch is, even when there is no touch going on. Make sure there is at least one finger touching the screen before you ask what the phase is. if (Input.touchCount > 0)
You probably want to separate the jumping action from the Touch. I would suggest a separate DoJump routine or similar. I see that you might be using the script from here. Did you get the example working, before you tried to make your customizations? Always start with something that works, then add your features Can someone help me make a simple jump script? - Questions & Answers - Unity Discussions
My project is 2D so this script doesn’t work, I have modified “Rigidbody” to “Rigidbody2D”, “ForceMode” to “ForceMode2D” and add “(Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began)” to touching the screen for jumping character. The character doesn’t jump.
here the new script:
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(Rigidbody2D))]
public class Jump : MonoBehaviour
{
public Vector3 jump;
public float jumpForce = 2.0f;
public bool Ground;
Rigidbody2D rb;
void Start()
{
rb = GetComponent<Rigidbody2D>();
jump = new Vector3(0.0f, 2.0f, 0.0f);
}
void OnCollisionStay()
{
Ground = true;
}
void Update()
{
if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began)
{
rb.AddForce(jump * jumpForce, ForceMode2D.Impulse);
Ground = false;
}
}
}
Le problème c’est que ton rigidbody est set a Kinematic. Kinematic est pas affecté par les forces et la gravité. Set le a dynamic et ça devrait fonctionner!
Est-ce que une de tes animations dans ton animator bouge la position du personage? Si oui, met l’animator a off (avec la checkbox) et regarde si ton saut fonctionne.
Quand tu dis que tu utilises ton iPhone, tu veux bien dire Unity Remote?
De mon cote, ton setup fonctionne bien.
Edit : Click la checkbox de ton rigidbody a “simulated”
De plus, tu veux probablement augmenter la masse, sinon ta tortue va explorer l’espace