- Home /
Adding javascript to objects via scripting question.
First, sorry for my poor English.
I have a question about using MonoScript,
what I want is create an object with javascript via Scripting.
so I put some Sprites, PhysicsMaterial2Ds, and some Javascripts in Resources folder,
and then do something like the following script:
static function CreateFan(position : Vector3) {
var gameObject : GameObject = new GameObject();
gameObject.transform.position = position;
gameObject.transform.localScale = Vector3(0.35, 0.35, 1);
var sr : SpriteRenderer = gameObject.AddComponent(SpriteRenderer);
sr.sprite = selfUtil.LoadSprite('/Barrier/Fan', 'Fan');
sr.sortingLayerName = 'Object';
sr.sortingOrder = 2;
var pc : PolygonCollider2D = gameObject.AddComponent(PolygonCollider2D);
pc.sharedMaterial = Resources.Load('Material/Air') as PhysicsMaterial2D;
var script : MonoScript = Resources.Load('Script/Barrier/FanScript') as MonoScript;
gameObject.AddComponent(script.GetClass());
var fanScript : FanScript = gameObject.GetComponent('FanScript') as FanScript;
fanScript.speed = 1800;
var rb : Rigidbody2D = gameObject.AddComponent(Rigidbody2D);
rb.isKinematic = true;
}
It work fine before I build this project,
when I build this project I got the following ERROR
The name 'MonoScript' does not denote a valid type ('not found').
I really dunno why, can someone give me a hint?
What is $$anonymous$$onoScript? Do you mean Behaviour? You can denote a script like this >>> myScript : Behaviour = new $$anonymous$$yScript ();
Your answer
![](https://koobas.hobune.stream/wayback/20220613123039im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Adding javascript to objects via scripting question. 0 Answers
Single enum class 1 Answer
Error Help ASAP! Please Help 1 Answer
Wrong with script 1 Answer
Script Error 1 Answer