Question by
subzer0 · Dec 27, 2015 at 11:05 AM ·
levelaccessprotection
Public void method is inaccessible due to its protection level
I am trying to access a method from another script, but I am getting the protection level error. Even though I made the method Public.
This is the method I want to access:
public void Shoot()
{
timer = 0f;
gunAudio.Play ();
gunLight.enabled = true;
faceLight.enabled = true;
gunParticles.Stop ();
gunParticles.Play ();
gunLine.enabled = true;
gunLine.SetPosition (0, transform.position);
shootRay.origin = transform.position;
shootRay.direction = transform.forward;
}
And I am trying to access it from another script with this line of code:
if (hit.transform.name == "MyObjectName" )
GameObject.Find("Gun").GetComponent<PlayerShooting>().Shoot();
How can I make this work ?
Thanks.
Comment
Please post the exact error message. We need the exact wording and the linenumber of the error. You can copy & paste it from the bottom half of the console window in Unity.
Also make sure you saved your file and you let Unity recompile your scripts properly.