“An instance of type ‘UnityEngine.Component’ is required to access non static member”

Updated on June 11, 2017 in [A] Unity Scripting
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
5 on June 7, 2017

Hello! 

I’m having trouble with a Vector3.lerp in my script. I was pretty sure that I did it all right, but I keep getting this error: ” BCE0020: An instance of type ‘UnityEngine.Component’ is required to access non static member ‘transform’.” 

What am I doing wrong? 

Here’s my script: 

#pragma strict
public static var hook : GameObject;
public var bulletSpeed = 20f;
static var bulletCounter : int = 0;
function Start ()
{
bulletCounter = 0;
}
 
function Update () 
{
if (Input.GetMouseButtonDown(0) && bulletCounter == 0)
 {
var clone = Instantiate(hook, transform.position, transform.rotation);
clone.GetComponent.<Rigidbody>().AddForce(transform.forward * bulletSpeed);
bulletCounter = 1;
Debug.Log("No more shooting");
 }
}
public static function Nyoom ()
{
transform.position = Vector3.Lerp(transform.position, hook.transform, 1000f);
}
  • Liked by
Reply
4 on June 7, 2017

Shouldn’t it be hook.transform.position?

 

on June 9, 2017

Yes, it is (Thank you for that), but I still get the error for some reason. 

Wise
on June 9, 2017

Is it the same error? Same line?

 

on June 11, 2017

Yeah, nothing changed. It’s so weird.

Wise
on June 11, 2017

Don’t know how I missed that, the Nyoom function is static, you can’t call non static members in a static function.

 

Show more replies
  • Liked by
Reply
Cancel