0

I thought what I was planning on doing was simple, but for some reason this function is not being defined correctly. It is something I have done before but this time it does not work. I have two C# scripts and I am trying to call a function from one within the other. What I have is this:

Script 1:

public class BulletScript : MonoBehaviour 
{
   private float angle;

   void Start() 
   {
        angle = 23f;
   }

   public float getAngle()
   {
        return angle;
   }
}

Script 2:

public class SMG : MonoBehaviour 
{
    private float angle;
    private BulletScript objectBulletScript;
    void Start () 
    {
        objectBulletScript = GetComponent<BulletScript>();
        angle = objectBulletScript.getAngle();
    }
}

There are various other elements in the scripts but this is the basis of where the fault is occuring. This is the only declaration of 'BulletScript' within this class. Everything else works appropriately and does not interact with this process. The error message I am getting is: 'BulletScript' does not contain a definition for 'getAngle()'

Does anyone have any ideas where I went wrong.

Grant Winney
  • 65,241
  • 13
  • 115
  • 165
user2740515
  • 89
  • 1
  • 2
  • 7
  • 5
    Have you tried using the fully qualified name? Maybe you have two `BulletScript` types? – DGibbs Aug 04 '14 at 14:17
  • Does it matter if I have a BulletScript type in a parent class? – user2740515 Aug 04 '14 at 15:01
  • What do you mean by parent class? If it is a class within a class (ie `class BulletScript { class BulletScript {} }, then yes, it does. But AFAIK unity wouldn't allow you to use the child monobehaviour as a component. – Krzysztof Bociurko Aug 04 '14 at 18:06

0 Answers0