您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
21 行
620 B
21 行
620 B
using UnityEngine;
|
|
using Unity.Robotics.ROSTCPConnector;
|
|
using RosColor = RosMessageTypes.UnityRoboticsDemo.UnityColorMsg;
|
|
|
|
public class RosSubscriberExample : MonoBehaviour
|
|
{
|
|
ROSConnection ros;
|
|
public GameObject cube;
|
|
|
|
void Start()
|
|
{
|
|
ros = ROSConnection.instance;
|
|
ros.RegisterSubscriber<RosColor>("color");
|
|
ros.Subscribe<RosColor>("color", ColorChange);
|
|
}
|
|
|
|
void ColorChange(RosColor colorMessage)
|
|
{
|
|
cube.GetComponent<Renderer>().material.color = new Color32((byte)colorMessage.r, (byte)colorMessage.g, (byte)colorMessage.b, (byte)colorMessage.a);
|
|
}
|
|
}
|