Skip to content

Instantly share code, notes, and snippets.

@Oleur
Created November 30, 2020 18:49
Show Gist options
  • Select an option

  • Save Oleur/59ec2dddab763b241d36f2ac2fa90695 to your computer and use it in GitHub Desktop.

Select an option

Save Oleur/59ec2dddab763b241d36f2ac2fa90695 to your computer and use it in GitHub Desktop.
class UnityGameActivity : UnityPlayerActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
mUnityPlayer += MaterialButton(this).apply {
...
text = "RANDOMIZE COLOR"
setOnClickListener {
val color = listOf("blue", "green", "red", "yellow").random()
UnityPlayer.UnitySendMessage("Capsule", "ChangeColor", color)
}
}
mUnityPlayer += MaterialButton(this).apply {
...
text = "QUIT"
setOnClickListener {
val intent = Intent(context, MainActivity::class.java).apply {
flags = Intent.FLAG_ACTIVITY_REORDER_TO_FRONT or Intent.FLAG_ACTIVITY_SINGLE_TOP
}
startActivity(intent)
}
}
mUnityPlayer += JoystickView(this).apply {
...
findViewById<View>(R.id.forward).setOnClickListener {
UnityPlayer.UnitySendMessage("Capsule", "MoveUp", "")
}
...
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment