关注

安卓调用unity中的方法

unity集成到安卓中:

https://blog.csdn.net/AllBluefm/article/details/155519181

unity调用安卓方法:

https://blog.csdn.net/AllBluefm/article/details/155520724

安卓调用unity中的方法,比如点击安卓上一个按钮,启动unity中一个动画

第一步:unity中需要写好脚本,并挂载到一个gameObject上,供安卓调用

using UnityEngine;

public class AnimationControl : MonoBehaviour
{
    private Animation anim;
    private string clipName = "Scene";

    void Start()
    {
        anim = GetComponent<Animation>();
    }

    void Update()
    {
    }

    // 播放动画,供安卓调用
    public void Play()
    {
        anim[clipName].time = 0f;
        anim[clipName].speed = 1f;
        anim.Play(clipName, PlayMode.StopSameLayer);
    }
}

第二步:在安卓中调用

// 播放动画
UnityPlayer.UnitySendMessage("model", "Play", "");

第一个参数:unity中AnimationControl 脚本挂载的gameObject名称

第二个参数:调用的方法

第三个参数:需要传到unity中的参数

转载自CSDN-专业IT技术社区

原文链接:https://blog.csdn.net/AllBluefm/article/details/155520167

评论

赞0

评论列表

微信小程序
QQ小程序

关于作者

点赞数:0
关注数:0
粉丝:0
文章:0
关注标签:0
加入于:--