Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.
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?

share|improve this question

1 Answer 1

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...
    }
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.