JavaScrpit:
// Public variable
public var speed : int = 6;
// Function called once when the bullet is created
function Start () {
// Get the rigidbody component
var r2d = GetComponent(“Rigidbody2D”);
// Make the bullet move upward
r2d.velocity.y = speed;
}
// Function called when the object goes out of the screen
function OnBecameInvisible() {
// Destroy the bullet Destroy(gameObject);
}
-------------------------------This is the original code i’m translating---------------------------------------------------------------
C#:
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using UnityEngine;
public class spaceshipScript : MonoBehaviour
{
// Function called about 60 times per second
void Update()
{
// Get the rigidbody component
type r2d(GetComponentNewStruct"Rigidbody2D"));
// Move the spaceship when an arrow key is pressed
if (Input object p3 = GetKey(“right”); object p2 = r2d.velocity.x(10);
else if (Input object p = GetKey(“left”); r2d.velocity.x(-10);
else
object p1 = r2d.velocity.x(0);
}
}
[DebuggerDisplay(“{” + nameof(GetDebuggerDisplay) + “(),nq}”)]
internal struct NewStruct
{
public object Item1;
public object Item2;
public NewStruct(object item1, object item2)
{
Item1 = item1;
Item2 = item2;
}
public override bool Equals(object obj)
{
return obj is NewStruct other &&
EqualityComparer.Default.Equals(Item1, other.Item1) &&
EqualityComparer.Default.Equals(Item2, other.Item2);
}
public override int GetHashCode()
{
int hashCode = -1030903623;
hashCode = hashCode * -1521134295 + EqualityComparer.Default.GetHashCode(Item1);
hashCode = hashCode * -1521134295 + EqualityComparer.Default.GetHashCode(Item2);
return hashCode;
}
public void Deconstruct(out object item1, out object item2)
{
item1 = Item1;
item2 = Item2;
}
public static implicit operator (object, object)(NewStruct value)
{
return (value.Item1, value.Item2);
}
public static implicit operator NewStruct((object, object) value)
{
return new NewStruct(value.Item1, value.Item2);
}
private string GetDebuggerDisplay()
{
return ToString();
}
}
This is what i’ve got until now, i still think it isn’t neir close.