【发布时间】:2014-08-12 12:39:31
【问题描述】:
我的场景有一个主角、一个气球和一个系绳。我有一个连接到气球的弹簧接头 2d,我希望能够将连接的主体更改为玩家单击的对象。到目前为止,我有以下 2 个脚本,一个用于气球,一个用于连接体:
气球:
using UnityEngine;
using System.Collections;
public class BalloonTethering : MonoBehaviour {
public SpringJoint2D theSpringJoint;
public Rigidbody2D theTether;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
theSpringJoint.connectedBody = theTether;
}
}
连接体:
using UnityEngine;
using System.Collections;
public class TetherAny : MonoBehaviour {
public GameObject mainBalloon;
public Rigidbody2D iAmATether = new Rigidbody2D();
// Use this for initialization
void Start () {
mainBalloon.GetComponents<BalloonTethering>();
iAmATether = this.gameObject.GetComponents<Rigidbody2D>();
}
// Update is called once per frame
void Update () {
}
void OnMouseDown(){
BalloonTethering.theTether = iAmATether;
}
}
我在 TetherAny 脚本上不断收到以下两个错误:
(12,17):错误 CS0029:无法将类型“UnityEngine.Rigidbody2D[]”隐式转换为“UnityEngine.Rigidbody2D”
(21,34):错误 CS0120:访问非静态成员“BalloonTethering.theTether”需要对象引用
如果有人能告诉我哪里出错了,将不胜感激:)
谢谢!
【问题讨论】:
标签: c# unity3d 2d game-physics