-1

How can I color that string in code

private void HandleChatSpam()
{
    PlayerScript playerScript = PlayerScript.FromPhoton(PhotonNetwork.player);
    playerScript.ChatMessage("mpgh.net - BlackBoom pub build");
}

How can I color text in line here ChatMessage("mpgh.net - BlackBoom pub build"); text that I want to color (green) is mpgh.net - BlackBoom pub build

I already tried:

playerScript.ChatMessage(Color.green, "mpgh.net - BlackBoom pub build");

But I get this error

no overload for method 'ChatMessage' takes 2 arguments

What is ChatMessage

private void ChatMessage(string)

it's in reference

CDspace
  • 2,639
  • 18
  • 30
  • 36
  • What version of unity are you using? Is it unity5 if so just grab the text object and change the color property – johnny 5 Mar 13 '17 at 20:30
  • Uh...is `ChatMessage()` a method from Photon? If that's the case, then you probably are stuck with what you've got. In that case, I recommend displaying this in a text field set to display Rich Text and working the colour in to the content you're sending. – Serlite Mar 13 '17 at 20:44
  • Check this maybe it can help: http://answers.unity3d.com/questions/592242/changing-color-of-a-string-1.html – I.B Mar 13 '17 at 21:15
  • it's method from photon – Piotr Krankiewicz Mar 14 '17 at 18:37

1 Answers1

2

You can use Unity Rich Text to color a string or parts of it.

In your case it would be :

playerScript.ChatMessage("<color=green>mpgh.net - BlackBoom pub build</color>");
I.B
  • 2,925
  • 1
  • 9
  • 22