Forum rules - please read before posting.

change BackgroundTexture color in a Menu element

Depending on a certain distance between Player and Enemy I want a Menu element (Label) Background Texture color to change.
I found this in your manual:
AC.PlayerMenus.GetElementWithName (string menuName, string menuElementName);
but that's as far as I understand.
 My menuName is EnemySees and the Element Name is: thisColor
How can I change the colors ?

Comments

  • You'll first need to have each colour as a separate texture, as you can't tweak the colour in the same texture.

    You're on the right track with the coding - that function returns the MenuElement class you want to change.  The parameters require the names, so:

    MenuElement thisColorElement = AC.PlayerMenus.GetElementWithName ("EnemySees", "thisColor");

    will give you a new MenuElement variable named thisColorElement you can manipulate.

    The scripting guide's entry on the MenuElement class can be found by searching for it in the top-right corner.  Scroll down and you'll find backgroundTexture in the list of variables.  You can amend its value with:

    thisColorElement.backgroundTexture = myNewTexture;

    where myNewTexture is a Texture2D variable you've defined at the top of your script.
  • It took me sometime because I am not too familiar with the AC. variety of functions BUT IT WORKS and thanks a lot.
    To finish this up I need also the Different Texts that go with each color:
    This is waht I have for the color change:








    MenuElement thisColorElement = AC.PlayerMenus.GetElementWithName ("EnemySees", "thisColor");

                    thisColorElement.backgroundTexture = attackTexture;
    where attackTexture is a public Texture2d.
    But, how about using the same procedure for displaying a text under Label Text of the same Menu element? there is no
    thisColorElement.LabelText = myText   ???



  • edited March 2017
    The MenuElement class is a base class for all element types.  Labels are of the type MenuLabel - you need to cast from one to the other.  This is a C# technique, and not one specific to AC:

    AC.MenuLabel myLabel = (AC.MenuLabel) thisColorElement;
    myLabel.label = myText;

  • I consider myself a genius in C language but never experienced nor needed object-oriented languages, c#, c++ etc to me AC scripts are difficult to grasp.
    Thanks again now I have my scene complete
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.