c# - Referencing a non static member with an instantiated object -


i want class render grid each time instantiated, getting error, error

cs0120: object reference required access non-static member `unityengine.gameobject.getcomponent(system.type)'

so instantiate object of renderer called rend , set equal non-static member still getting error? appreciated have researched several hours , still can't figure out.

using unityengine; using system.collections;  public class setgrid : monobehaviour {      public int x = 1;     public int y = 1;      void start()     {         renderer rend = gameobject.getcomponent<renderer>().material.maintexturescale = new vector2 (x, y);      } } 

i assuming script part of grid game object has component of type renderer.

the correct syntax scale texture of renderer following:

public class setgrid : monobehaviour {      public int x = 1;     public int y = 1;      void start()     {         // reference renderer component of game object.         renderer rend = getcomponent<renderer>();         // scale texture.         rend.material.maintexturescale = new vector2 (x, y);     } } 

the error message thrown because tried call getcomponent on type of gameobject , not instance of gameobject. script in context of gameobject meaning can access component getcomponent non-static method.


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -