I’m trying to create a movement script for an isometric game, I’ve watched a tutorial for this as I am a beginner in coding and unity, I managed to make the “character” (a box as a placeholder) move around, but did not manage to create a jump script, I get the error "error CS1525: Unexpected symbol `else’ "
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CharController : MonoBehaviour {
[SerializeField]
public float moveSpeed = 4f;
Vector3 forward, right;
public bool jump = false;
public float jumpHeight = 8f, jumpSpeed = 10f;
Rigidbody rb;
void Start ()
{
forward = Camera.main.transform.forward;
forward.y = 0;
forward = Vector3.Normalize(forward);
right = Quaternion.Euler(new Vector3(0, 90, 0)) * forward;
rb = GetComponent<Rigidbody>();
}
void Update ()
{
if (Input.GetButtonDown("Jump") && !jump)
else
Move();
}
void Move()
{
Vector3 direction = new Vector3(Input.GetAxis("HorizontalKey"), 0, Input.GetAxis("VerticalKey"));
Vector3 rightMovement = right * moveSpeed * Time.deltaTime * Input.GetAxis("HorizontalKey");
Vector3 upMovement = forward * moveSpeed * Time.deltaTime * Input.GetAxis("VerticalKey");
Vector3 heading = Vector3.Normalize(rightMovement + upMovement);
transform.forward = heading;
transform.position += rightMovement;
transform.position += upMovement;
}
IEnumerator Jump()
{
float originalHeight = transform.position.y;
jump = true;
yield return null;
//rb.usegravity - false; // disable gravity so we can move our transform without resistance
rb.AddForce(Vector3.up * jumpHeight, ForceMode.Impulse);
//float maxHeight - originalHeight + jumpHeight;
/*while(transform.position.y < maxHeight)
* {
* transform.position += tranform.up * Time.deltaTime * jumpSpeed;
* yield return null;
* {
*/
//rb.useGravity = true;
while (transform.position.y > originalHeight)
{
transform.position -= transform.up * Time.deltaTime * jumpSpeed;
yield return null;
rb.useGravity = true;
jump = false;
yield return null;
}
}
}