using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class Helper : MonoBehaviour
{
NavMeshAgent navMeshAgent;
Zombie zombie;
Helper helper;
CapsuleCollider capsuleCollider;
Animator animator;
MovementAnimator movementAnimator;
float speed;
// Start is called before the first frame update
void Start()
{
speed = animator.SetFloat("speed", navMeshAgent.velocity.magnitude);
navMeshAgent = GetComponent<NavMeshAgent>();
zombie = FindObjectOfType<Zombie>();
navMeshAgent.updateRotation = false;
capsuleCollider = GetComponent<CapsuleCollider>();
animator = GetComponentInChildren<Animator>();
movementAnimator = GetComponent<MovementAnimator>();
}
// Update is called once per frame
void Update()
{
if (speed == 0) {
zombie = FindObjectOfType<Zombie>();
}
navMeshAgent.SetDestination(zombie.transform.position);
transform.rotation = Quaternion.LookRotation(navMeshAgent.velocity.normalized);
}
}
CS0029: Cannot implicitly convert type âvoidâ to âfloatâ (19,17)
I think your error is in a different file. What file does the error say itâs in?
The error says that itâs in this file (above)
Why do you think itâs in different file?
Because I copied your script into Visual studio and didnât see any errors except that Zombie, Helper, and MovementAnimator are undefined (I donât have scripts with those names). Didnât see your error. And I personally donât see any compile issues with what you posted here. Did you forget to save changes to the file maybe?
error in
speed = animator.SetFloat(âspeedâ, navMeshAgent.velocity.magnitude);
use
animator.SetFloat(âspeedâ, navMeshAgent.velocity.magnitude);
1 Like
Assets\Scripts\Helper.cs(14,11): warning CS0649: Field âHelper.speedâ is never assigned to, and will always have its default value 0
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class Helper : MonoBehaviour
{
NavMeshAgent navMeshAgent;
Zombie zombie;
Helper helper;
CapsuleCollider capsuleCollider;
Animator animator;
MovementAnimator movementAnimator;
float speed;
// Start is called before the first frame update
void Start()
{
animator.SetFloat("speed", navMeshAgent.velocity.magnitude);
navMeshAgent = GetComponent<NavMeshAgent>();
zombie = FindObjectOfType<Zombie>();
navMeshAgent.updateRotation = false;
capsuleCollider = GetComponent<CapsuleCollider>();
animator = GetComponentInChildren<Animator>();
movementAnimator = GetComponent<MovementAnimator>();
}
// Update is called once per frame
void Update()
{
if (speed == 0) {
zombie = FindObjectOfType<Zombie>();
}
navMeshAgent.SetDestination(zombie.transform.position);
transform.rotation = Quaternion.LookRotation(navMeshAgent.velocity.normalized);
}
}
k7lisenk:
Assets\Scripts\Helper.cs(14,11): warning CS0649: Field âHelper.speedâ is never assigned to, and will always have its default value 0
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class Helper : MonoBehaviour
{
NavMeshAgent navMeshAgent;
Zombie zombie;
Helper helper;
CapsuleCollider capsuleCollider;
Animator animator;
MovementAnimator movementAnimator;
float speed;
// Start is called before the first frame update
void Start()
{
animator.SetFloat("speed", navMeshAgent.velocity.magnitude);
navMeshAgent = GetComponent<NavMeshAgent>();
zombie = FindObjectOfType<Zombie>();
navMeshAgent.updateRotation = false;
capsuleCollider = GetComponent<CapsuleCollider>();
animator = GetComponentInChildren<Animator>();
movementAnimator = GetComponent<MovementAnimator>();
}
// Update is called once per frame
void Update()
{
if (speed == 0) {
zombie = FindObjectOfType<Zombie>();
}
navMeshAgent.SetDestination(zombie.transform.position);
transform.rotation = Quaternion.LookRotation(navMeshAgent.velocity.normalized);
}
}
Thatâs because youâre never changing the value of âspeedâ. Itâs just a warning though. The game should run, it just wonât behave the way you want.