Ajuda erro em bool IsGrounded()
Página 1 de 1
Ajuda erro em bool IsGrounded()
\Script\PlayerMoviment.cs(65,13): error CS0428: Cannot convert method group 'IsGrounded' to non-delegate type 'bool'. Did you intend to invoke the method?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMoviment : MonoBehaviour
{
CharacterController characterController;
Animator animator;
[SerializeField] float walkSpeed;
[SerializeField] float runSpeed;
[SerializeField] float turnSpeed;
[SerializeField] float animSpeed;
[SerializeField] float jumpSpeed;
[SerializeField] float gravity;
[SerializeField] float floorDistance;
Vector3 verticalVector;
bool isRunning;
// Start is called before the first frame update
void Start()
{
characterController = GetComponent<CharacterController>();
animator = GetComponent<Animator>();
verticalVector = Vector3.zero;
}
// Update is called once per frame
void Update()
{
isRunning = Input.GetKey(KeyCode.LeftShift);
Move();
VerticalMovement();
}
void Move()
{
float horizontal = Input.GetAxis("Horizontal") * GetCurrentSpeed() * Time.deltaTime;
float vertical = Input.GetAxis("Vertical") * GetCurrentSpeed() * Time.deltaTime;
Vector3 moveVector = new Vector3(horizontal, 0f, vertical);
characterController.Move(moveVector);
animator.SetFloat("Speed", moveVector == Vector3.zero? 0f : (isRunning? 1f : .5f), animSpeed, Time.deltaTime);
if(moveVector != Vector3.zero)
Rotate(moveVector);
}
void Rotate(Vector3 moveVector)
{
Quaternion targetRotation = Quaternion.LookRotation(moveVector, Vector3.up);
Quaternion newRotation = Quaternion.Lerp(transform.rotation, targetRotation, turnSpeed * Time.deltaTime);
transform.rotation = newRotation;
}
void VerticalMovement()
{
if (IsGrounded)
{
if(Input.GetButtonDown("Jump"))
{
verticalVector.y = jumpSpeed;
animator.SetTrigger("Jump");
}
else if (verticalVector.y < 0)
verticalVector.y = 0;
}
else
verticalVector.y -= gravity * Time.deltaTime;
characterController.Move(verticalVector);
}
bool IsGrounded()
{
RaycastHit hit;
if(Physics.Raycast(transform.position, Vector3.down, out hit))
return hit.distance <= floorDistance;
return false;
}
float GetCurrentSpeed()
{
return isRunning ? runSpeed : walkSpeed;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMoviment : MonoBehaviour
{
CharacterController characterController;
Animator animator;
[SerializeField] float walkSpeed;
[SerializeField] float runSpeed;
[SerializeField] float turnSpeed;
[SerializeField] float animSpeed;
[SerializeField] float jumpSpeed;
[SerializeField] float gravity;
[SerializeField] float floorDistance;
Vector3 verticalVector;
bool isRunning;
// Start is called before the first frame update
void Start()
{
characterController = GetComponent<CharacterController>();
animator = GetComponent<Animator>();
verticalVector = Vector3.zero;
}
// Update is called once per frame
void Update()
{
isRunning = Input.GetKey(KeyCode.LeftShift);
Move();
VerticalMovement();
}
void Move()
{
float horizontal = Input.GetAxis("Horizontal") * GetCurrentSpeed() * Time.deltaTime;
float vertical = Input.GetAxis("Vertical") * GetCurrentSpeed() * Time.deltaTime;
Vector3 moveVector = new Vector3(horizontal, 0f, vertical);
characterController.Move(moveVector);
animator.SetFloat("Speed", moveVector == Vector3.zero? 0f : (isRunning? 1f : .5f), animSpeed, Time.deltaTime);
if(moveVector != Vector3.zero)
Rotate(moveVector);
}
void Rotate(Vector3 moveVector)
{
Quaternion targetRotation = Quaternion.LookRotation(moveVector, Vector3.up);
Quaternion newRotation = Quaternion.Lerp(transform.rotation, targetRotation, turnSpeed * Time.deltaTime);
transform.rotation = newRotation;
}
void VerticalMovement()
{
if (IsGrounded)
{
if(Input.GetButtonDown("Jump"))
{
verticalVector.y = jumpSpeed;
animator.SetTrigger("Jump");
}
else if (verticalVector.y < 0)
verticalVector.y = 0;
}
else
verticalVector.y -= gravity * Time.deltaTime;
characterController.Move(verticalVector);
}
bool IsGrounded()
{
RaycastHit hit;
if(Physics.Raycast(transform.position, Vector3.down, out hit))
return hit.distance <= floorDistance;
return false;
}
float GetCurrentSpeed()
{
return isRunning ? runSpeed : walkSpeed;
}
}
RenanHero- Iniciante
- PONTOS : 2005
REPUTAÇÃO : 6
Idade : 24
Respeito as regras :
Re: Ajuda erro em bool IsGrounded()
foi só mudar o de cima pra
if (IsGrounded())
o erro bobo
if (IsGrounded())
o erro bobo
RenanHero- Iniciante
- PONTOS : 2005
REPUTAÇÃO : 6
Idade : 24
Respeito as regras :
Tópicos semelhantes
» [AJUDA] Erro Unity!
» (Ajuda) NavMesh erro.
» [AJUDA]Quero Ajuda poque esse script so da erro!
» AD-MOB ERRO >>>> AJUDA
» Ajuda erro
» (Ajuda) NavMesh erro.
» [AJUDA]Quero Ajuda poque esse script so da erro!
» AD-MOB ERRO >>>> AJUDA
» Ajuda erro
Página 1 de 1
Permissões neste sub-fórum
Não podes responder a tópicos