Unity Ninja Unity 3D Forum
To have exclusive access to all downloads, recourses and links within this forum, a free registered account is required. Just a heads up Wink
Share
Go down
Member [Lv. 1]
Member [Lv. 1]
Posts : 3
Points : 1143
Rep : 0
Join date : 2015-06-12
View user profile

Please help! Scripts

on Sat Jun 13, 2015 10:34 am
wht's wron? Wherr's the erro? PLEASE Exclamation Exclamation Exclamation Exclamation Exclamation Exclamation Exclamation

using UnityEngine;
using System.Collections;

public class MenuObject : MonoBehaviour {

public bool isStartGame = false;
public bool isExit = false;

void Start() {
renderer.material.color = Color.red;
}

// Change text colors
void OnMouseEnter() {
renderer.material.color = Color.yellow;
}

void OnMouseExit() {
renderer.material.color = Color.red;
}

// Click actions
void OnMouseDown() {
if (isStartGame) {
Application.LoadLevel(1);
}
if (isExit) {
Application.Quit();
}
}
}




Note: I'm brazilian
avatar
Moderator
Moderator
Posts : 329
Points : 2177
Rep : 43
Join date : 2014-03-12
Age : 18
Location : Italy
View user profilehttp://masterdevelopers.altervista.org/

Re: Please help! Scripts

on Sat Jun 13, 2015 12:58 pm
0 errors
avatar
Moderator
Moderator
Posts : 329
Points : 2177
Rep : 43
Join date : 2014-03-12
Age : 18
Location : Italy
View user profilehttp://masterdevelopers.altervista.org/

Re: Please help! Scripts

on Sat Jun 13, 2015 12:58 pm
The script works
Member [Lv. 1]
Member [Lv. 1]
Posts : 3
Points : 1143
Rep : 0
Join date : 2015-06-12
View user profile

Re: Please help! Scripts

on Sun Jun 14, 2015 7:35 am
Ok, thanks. I will try again. confused study Exclamation
avatar
{SUPER MEMBER}-LV.4
{SUPER MEMBER}-LV.4
Posts : 53
Points : 1530
Rep : 11
Join date : 2015-01-18
Age : 41
Location : Italia
View user profile

Re: Please help! Scripts

on Tue Jun 23, 2015 4:57 pm
not that you have renamed the script?
the script name in c # should be like class.

"public class MenuObject: MonoBehaviour{"

file name:
MenuObject.cs

hello Very Happy
avatar
Moderator
Moderator
Posts : 329
Points : 2177
Rep : 43
Join date : 2014-03-12
Age : 18
Location : Italy
View user profilehttp://masterdevelopers.altervista.org/

Re: Please help! Scripts

on Wed Jun 24, 2015 4:05 am
PitbullM wrote:not that you have renamed the script?
the script name in c # should be like class.

"public class MenuObject: MonoBehaviour{"

file name:
MenuObject.cs

hello Very Happy
Yes sure Wink
avatar
Admin
Admin
Posts : 608
Points : 3170
Rep : 406
Join date : 2013-12-11
Age : 21
View user profilehttps://www.youtube.com/user/misterninjaboy

Re: Please help! Scripts

on Wed Jun 24, 2015 2:28 pm
Please post something like this in "help" section next time. Scripts section is for sharing resources, not asking for help.
avatar
Admin
Admin
Posts : 608
Points : 3170
Rep : 406
Join date : 2013-12-11
Age : 21
View user profilehttps://www.youtube.com/user/misterninjaboy

Re: Please help! Scripts

on Wed Jun 24, 2015 2:28 pm
moved.
avatar
Member [Lv. 3]
Member [Lv. 3]
Posts : 45
Points : 1398
Rep : 3
Join date : 2015-08-30
Age : 23
Location : Melbourne
View user profilehttp://jakeaquilina.weebly.com/

Re: Please help! Scripts

on Mon Aug 31, 2015 10:50 am
in unity 5 you need to GetComponent




Code:

using UnityEngine;
using System.Collections;

public class MenuObject : MonoBehaviour
{

    public bool isStartGame = false;
    public bool isExit = false;

    void Start()
    {
        GetComponent<Renderer>().material.color = Color.red;
    }

    // Change text colors
    void OnMouseEnter()
    {
        GetComponent<Renderer>().material.color = Color.yellow;
    }

    void OnMouseExit()
    {
        GetComponent<Renderer>().material.color = Color.red;
    }

    // Click actions
    void OnMouseDown()
    {
        if (isStartGame)
        {
            Application.LoadLevel(1);
        }
        if (isExit)
        {
            Application.Quit();
        }
    }
}
avatar
SUPER MODERATOR
SUPER MODERATOR
Posts : 279
Points : 2142
Rep : 58
Join date : 2013-12-16
Age : 17
Location : Boise Idaho United States
View user profile

Re: Please help! Scripts

on Mon Aug 31, 2015 4:35 pm
Hi GGG22, welcome to Unity Ninja! Let me start of with saying that
I believe there might be an easier way with changing the rendered material, I believe it is with the MeshRenderer function. However, yes I would look back on the filename as PitbullM mentioned. Make sure both names match the classname and the actual filename in your project.
(Quick Edit)
aquilinajake brings up an interesting subject as Unity 5 utilizes the GetComponent function and no longer utilizes the MeshRenderer function for changing materials at least.

There are quite the few options, just need to here back from ya Smile

-BryceCain25
Back to top
Permissions in this forum:
You cannot reply to topics in this forum