Calling a Unity Function from Java

I am new to unity:

I create a simple cube in Unity and overlay some texture. I rotate the cube ... move the camera .... then export to android studio. When I run everything, it looks like Unity.

But I want to move the camera or cube from the Android studio code (programming line), and I cannot find any way ... findearchById or similar to find my cube :)

I am trying to create a C # file (I just put it in the resources folder) and put:

public class test : MonoBehaviour {
public GameObject respawn;
void Start () {

    Debug.Log("aaaaaaaaaaaaa1111111111111111");
    if (respawn == null)
        respawn = GameObject.FindWithTag("mamaie");


    respawn.transform.Rotate(10f, 50f, 10f);

}

// Update is called once per frame
void Update () {
    transform.Rotate(10f, 50f, 10f);
}

void LateUpdate()
{
    transform.Rotate(10f, 50f, 10f);
}
}

So ... how can I control my cube (developed in unity and imported into android studio) from programming lines?

+1
source share
1 answer

# Java UnityPlayer.UnitySendMessage.

:

UnityPlayer.UnitySendMessage("GameObjectName", "MethodName", "parameter to send");

, classes.jar <UnityInstallDirectory>\Editor\Data\PlaybackEngines\AndroidPlayer\Variations\mono\Release\Classes Android Studio, import com.unity3d.player.UnityPlayer; Android Studio.

#:

bool rotate = false;

void startRotating()
{
    rotate = true;
}

void stopRotating()
{
    rotate = false;
}

void Update()
{
    if (rotate)
        transform.Rotate(10f, 50f, 10f);
}

, script GameObject "Cube".

Java:

UnityPlayer.UnitySendMessage("Cube", "startRotating", null);

Java:

UnityPlayer.UnitySendMessage("Cube", "stopRotating", null);
+1

Source: https://habr.com/ru/post/1676930/


All Articles