How do i Fix 'UnityEngine.component.rigidbody' is a property but a 'type' was declared?
I'm fairly new to unity and I'm going through the tank Tut, and I finish the script for firing but I get a error message 'Unity Engine.Component.rigid body' is a property but a 'type' was declared and also a local variable 'shell instance' cannot be used before it is declared. any help would be appreciated.
,
Answer by cstooch · Jun 24, 2017 at 04:33 PM
You need to post some code. You're expecting someone to fix errors in code when we have no idea what it is you typed. These errors almost always say line numbers though. Check the line that the error is pointing to. Based on the error, it looks like you have a space in the variable name, or your case (upper/lower case) is wrong, or something.
using UnityEngine;
using UnityEngine.UI;
public class TankShooting : $$anonymous$$onoBehaviour
{
public int m_PlayerNumber = 1;
public Rigidbody m_Shell;
public Transform m_FireTransform;
public Slider m_AimSlider;
public AudioSource m_ShootingAudio;
public AudioClip m_ChargingClip;
public AudioClip m_FireClip;
public float m_$$anonymous$$inLaunchForce = 15f;
public float m_$$anonymous$$axLaunchForce = 30f;
public float m_$$anonymous$$axChargeTime = 0.75f;
private string m_FireButton;
private float m_CurrentLaunchForce;
private float m_ChargeSpeed;
private bool m_Fired;
private void OnEnable()
{
m_CurrentLaunchForce = m_$$anonymous$$inLaunchForce;
m_AimSlider.value = m_$$anonymous$$inLaunchForce;
}
private void Start()
{
m_FireButton = "Fire" + m_PlayerNumber;
m_ChargeSpeed = (m_$$anonymous$$axLaunchForce - m_$$anonymous$$inLaunchForce) / m_$$anonymous$$axChargeTime;
}
private void Update()
{
// Track the current state of the fire button and make decisions based on the current launch force.
m_AimSlider.value = m_$$anonymous$$inLaunchForce;
if (m_CurrentLaunchForce >= m_$$anonymous$$axLaunchForce && !m_Fired)
{
m_CurrentLaunchForce = m_$$anonymous$$axLaunchForce;
Fire();
}
else if (Input.GetButtonDown(m_FireButton))
{
m_Fired = false;
m_CurrentLaunchForce = m_$$anonymous$$inLaunchForce;
m_ShootingAudio.clip = m_ChargingClip;
m_ShootingAudio.Play();
}
else if (Input.GetButton(m_FireButton) && !m_Fired)
{
m_CurrentLaunchForce += m_ChargeSpeed * Time.deltaTime;
m_AimSlider.value = m_CurrentLaunchForce;
}
else if (Input.GetButtonUp(m_FireButton) && !m_Fired)
{
Fire();
}
}
private void Fire()
{
// Instantiate and launch the shell.
m_Fired = true;
rigidbody shellInstance = Instantiate(m_Shell, m_FireTransform, m_FireTransform.rotation) as Rigidbody;
shellInstance.velocity = m_CurrentLaunchForce * m_FireTransform.forward;
m_ShootingAudio.clip = m_FireClip;
m_ShootingAudio.Play();
m_CurrentLaunchForce = m_$$anonymous$$inLaunchForce;
}
}
You marked this as answered, was that by accident, or did you manage to figure it out?
If not, I think you will fix both errors by capitalizing the r at the beginning of this line:
rigidbody shellInstance = Instantiate(m_Shell, m_FireTransform, m_FireTransform.rotation) as Rigidbody;