What is wrong in this line?,So what do i do wrong XD

hello guys. I am new to unity and feel a bit lost atm. Can someone take this thing apart and tell me why its not working?

GameObject.Find(“Projectile”).GetComponent().projectiledmg;

public class WeaponDMG : MonoBehaviour
{
public int projectiledmg = 10;
}

So what i am trying to do is to take the value of “projectiledmg” and use it in another script.

So i used GameObject.Find to get the object. GetComponent should grant me acces to the script with the name “WeaponDMG” and the end ().projectiledmg should finaly get the value.

But since its not working i assume i did somethign wrong.

any advise apreciated.

It’s hard to know what’s wrong, but here are some things it might be:

You never told the GetComponent function what type of component to retrieve.

In order to get a component using GetComponent you need to tell it what type of component to retrieve like this:

GameObject.Find("Projectile").GetComponent<WeaponDMG>().projectiledmg;

Maybe there isn’t any GameObject in the scene called ‘Projectile’

Another issue could be that there isn’t any GameObject called Projectile in the scene at the time you call GameObject.Find(). Make sure it actually exists and that there is no typos in the name.

I’m not sure if that’s your actual script or if it’s a part of it. But the way I would do what you’re trying to is probably something along the lines of this:

public class SomeName : MonoBehaviour
{
    private void Start()
    {
        GameObject.Find("Projectile").GetComponent<WeaponDMG>().projectiledmg = 10;
    }
}

You missed angle brackets and your WeaponDMG script name.

GameObject.Find("Projectile").GetComponent<WeaponDMG>().projectiledmg;

So if you want to take a value of projectiledmg from WeaponDMG script and use it in your another script, it can look like this:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AnotherScript: MonoBehaviour
{
	private int projectiledmg;
	
	private void Start()
	{
		projectiledmg = GameObject.Find("Projectile").GetComponent<WeaponDMG>().projectiledmg;
	}
}