- Home /
Question by
Pultz · May 16, 2013 at 10:19 AM ·
c#javascriptvs
JS to C# need help!
if(other.tag == "Ammo")
{
ShootObject.GetComponent(Shoot).ammo +=10;
Destroy(other.gameObject);
}
that is my JS scripts code
if(other.tag == "Ammo")
{
ShootObject.GetComponent(Shoot).ammo += 10;
Destroy(other.gameObject);
}
and that is the C# code
and i get this error.
Assets/Scripts/Player.cs(44,50): error CS0119: Expression denotes a type', where a
variable', value' or
method group' was expected
Comment
thanks i got a problem that maybe is the same but cant see it.
if(ammo > 0)
{
ammo --;
var projectile = Instantiate(shot, transform.position, Quaternion.identity);
projectile.rigidbody.AddForce(transform.forward * 1500);
}
JS code.
if(ammo > 0)
{
ammo --;
var projectile = Instantiate(shot, transform.position, Quaternion.identity);
projectile.rigidbody.AddForce(transform.forward * 1500);
}
C# code
thanks for the help
IF AN ANSWER HELPED, CLIC$$anonymous$$ THE "TIC$$anonymous$$" (not thumb) BUTTON TO $$anonymous$$A$$anonymous$$R IT CORRECT
for instansiate function you need to do somehting like thise:
GameObject projectile = Instantiate(params) as GameObject;
Best Answer
Answer by TheDarkVoid · May 16, 2013 at 10:29 AM
In C# GetComponent Works a bit differet.
GetComponent<Type>();
Here is what you should have:
if(other.tag == "Ammo")
{
ShootObject.GetComponent<Shoot>().ammo += 10;
Destroy(other.gameObject);
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613102347im_/https://answers.unity.com/themes/thub/images/avi.jpg)