【发布时间】:2018-07-05 15:33:26
【问题描述】:
Unity3D 2018.1.6
该脚本最初是 javascript,但将其转换为 csharp。现在我的班级有一个错误,说我使用了“扩展”是出乎意料的
错误
意外符号“扩展”
例如,我尝试了两种使用 extends 的方法,例如 javascript
第一种方式 1)
public class ScriptOne : MonoBehaviour {
//
}
class ScriptOne extends Object {
//
}
第二种方式2)
public class ScriptTwo extends Object : MonoBehaviour {
//
}
两种方式都给了我同样的错误。
这是从 .js 转换为 .cs 的脚本之一
using UnityEngine;
using System.Collections;
public class OrbitState extends Object : MonoBehaviour {
//================================//
//=== Orbit State datatype ===//
//================================//
/*
The OrbitState is the initial state of the orbiter at a particular point along the ellipse
The state contains all of the information necessary to apply a force to get the orbiter moving along the ellipse
*/
Vector3 position; // local position relative to the object we're orbiting around
Vector3 normal;
Vector3 tangent;
Vector3 velocity;
private Orbiter orbiter;
private OrbitalEllipse ellipse;
//==== Instance Methods ====//
// Constructor
void OrbitState ( float angle , Orbiter orbiter , OrbitalEllipse ellipse )
{
Update(angle, orbiter, ellipse);
}
// Update the state of the orbiter when its position along the ellipse changes
// Note: Make sure the ellipse is up to date before updating the orbit state
void Update ( float orbiterAngle , Orbiter orbiter , OrbitalEllipse ellipse )
{
this.orbiter = orbiter;
this.ellipse = ellipse;
this.normal = CalcNormal(orbiterAngle);
this.tangent = CalcTangent(normal);
this.position = ellipse.GetPosition(orbiterAngle, orbiter.orbitAround.position);
this.velocity = CalcVelocity(orbiter.orbitSpeed * orbiter.GravityConstant(), position, orbiter.orbitAround.position);
}
//==== Private Methods ====//
// Returns the normal on the ellipse at the given angle
// Assumes a vertical semi-major axis, and a rotation of 0 at the top of the ellipse, going clockwise
private Vector3 CalcNormal ( float rotationAngle )
{
// Part 1: Find the normal for the orbiter at its starting angle
// Rotate an upward vector by the given starting angle around the ellipse. Gives us the normal for a circle.
Vector3 localNormal = Quaternion.AngleAxis(rotationAngle, Vector3.forward*-1) * Vector3.up;
// Sqash the normal into the shape of the ellipse
localNormal.x *= ellipse.semiMajorAxis/ellipse.semiMinorAxis;
// Part 2: Find the global rotation of the ellipse
float ellipseAngle = Vector3.Angle(Vector3.up, ellipse.difference);
if (ellipse.difference.x < 0)
ellipseAngle = 360-ellipseAngle; // Full 360 degrees, rather than doubling back after 180 degrees
// Part 3: Rotate our normal to match the rotation of the ellipse
Vector3 globalNormal = Quaternion.AngleAxis(ellipseAngle, Vector3.forward*-1) * localNormal;
return globalNormal.normalized;
}
private Vector3 CalcTangent ( Vector3 normal )
{
float angle = 90;
int direction = orbiter.counterclockwise ? -1 : 1;
FIXME_VAR_TYPE tangent= Quaternion.AngleAxis(angle*direction, Vector3.forward*-1) * normal;
return tangent;
}
private Vector3 CalcVelocity ( float gravity , Vector3 orbiterPos , Vector3 orbitAroundPos )
{
// Vis Viva equation
float speed = Mathf.Sqrt( gravity * (2/Vector3.Distance(orbiterPos, orbitAroundPos) - 1/ellipse.semiMajorAxis ) );
Vector3 velocityVec = tangent * speed;
return velocityVec;
}
}
我有第二个脚本有同样的错误,但在解决一个脚本时我确信我可以解决另一个。
感谢您的帮助!
【问题讨论】:
-
最好将我们链接到原始的Javascript代码或将其发布在这里
-
除非我错过了什么,extends 不是 C# 关键字
-
@PassetCronUs wiki.unity3d.com/index.php/Simple_planetary_orbits 给你
标签: javascript c# unity3d inheritance extends