Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by pdunton · Feb 06, 2014 at 04:37 AM · javascriptgameobjectobjectrenderer

How to acsess the renderer of an Instantiate()

I need to acsess the renderer of an object that I Instatiate() and It keeps saying that "renderer" is not a member of "Object".`enter code here`

See the code below for the script. Thanks!

     #pragma strict
     var xpos : float;
     var spawnpoint : Vector3;
     var coin : GameObject;
     var rotation : Quaternion;
     rotation.eulerAngles = new Vector3(0, 0, 0);
     var newCoin :Object;
     
     function Start () {
     InvokeRepeating("CreateCoin", 1, 1);
     }
     
     function Update () {
     Destroy(GameObject.FindWithTag("Coin"),10);
     }
     
     function CreateCoin(){
         xpos = Random.Range(-50.0,50.0);
         spawnpoint = new Vector3(xpos, 80, 0);
         
         var myColor : Color;                       // This is just working for another part of my script, Please Ignore.
         var mode : boolean = Random.value > 0.5f;
         var rand : float = Random.value;
         var index : int = Random.Range( 0, 3 ); 
         myColor[index] = rand;
         myColor[( index + ( mode ? 1 : 2 ) ) % 3] = 1;
         myColor[( index + ( mode ? 2 : 1 ) ) % 3] = 0;
         
         newCoin = Instantiate(coin, spawnpoint, rotation);
         //newCoin = newCoin as GameObject; 
         newCoin.renderer.material.color = myColor;
         
     }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by pdunton · Feb 06, 2014 at 05:04 AM

Hey, for some reason I cannot comment.... So this is a comment. Ill try to look up how to fix it but it just keeps saying 10 Characters needed even though I type >10.

But I've tried that and It says that I forgot to put in a semicolon at the end of that line. Here's what it reads now...

 newCoin = (GameObject)Instantiate(coin, spawnpoint, rotation);
Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image zee_ola05 · Feb 06, 2014 at 07:11 AM 0
Share

You should also change

 var newCoin :Object;

to

 var newCoin : GameObject;
avatar image pdunton · Feb 07, 2014 at 03:22 AM 0
Share

Apperently my commenting fixed? Anyways, I changed the type to GameObject as you suggested, and the same is happening, I keep getting the "Assets/Resources/Scripts/CoinCreater.js(29,31): UCE0001: ';' expected. Insert a semicolon at the end. " error. :(

avatar image pdunton · Feb 07, 2014 at 04:04 AM 0
Share

Uhhhhh... I tried a couple of things, and it turns out, the correct thing to do is to have

 var newCoin : GameObject;

but not have

 newCoin = (GameObject)Instantiate(coin, spawnpoint, rotation);

Wierd, huh? Anyway, thanks a ton!

avatar image
0

Answer by zee_ola05 · Feb 06, 2014 at 04:39 AM

Instantiate returns an Object class, not a GameObject. So you simply cast.

 newCoin = (GameObject)Instantiate(coin, spawnpoint, rotation);
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

19 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

javascript to C#, UnityEngine.Object to GameObject? 1 Answer

multithread constructor call create gameObject 2 Answers

GameObject turns into Object in Array 1 Answer

Collider2D.GetContacts() always returns only 1 contact 1 Answer

OnCollisionEnter Collision not detected? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges