-2
\$\begingroup\$
public class player
{      public projectile pro;
       pro = GetComponent<projectile>();
    void Update()
    {
        GameObject go = GameObject.Find("enemy");
        Transform playerTransform = go.transform;
        Vector3 posi = playerTransform.position;
        pro.Target = posi;             // getting error here
        Instantiate(bulletprefab, position, Quaternion.identity);   
    }
}

Target is present is Projectile class and is Vector3 only, how to fix this error?

\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

You can't put or execute statements during the class declaration. Why is projectile public? If you are assigning the variable from the editor, delete the third line and assign it. Otherwise, make it public and assign it manually from the Awake method.

public class Player : MonoBehaviour
{
    private Projectile pro;

    private void Awake()
    {
        pro = GetComponent<Projectile>();
    }

    private void Update()
    {
         //update statements...
    }
}
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .