I have done this code in C sharp:
using UnityEngine;
using System.Collections;
public class SmoothFollow2 : MonoBehaviour
{
public Transform target;
public float smoothTime = 0.5F;
public static Vector2 yVelocity;
private float newPositiony;
private float newPositionx;
private Transform thisTransform;
void Start()
{
//thisTransform = transform;
}
void Update() {
newPositiony = Mathf.SmoothDamp(thisTransform.position.y, target.position.y, ref yVelocity.y, smoothTime);
newPositionx = Mathf.SmoothDamp(thisTransform.position.x, target.position.x, ref yVelocity.x, smoothTime);
if (newPositiony > thisTransform.position.y)
{
HeroAnimate.Heroindex = 2;
}
if (newPositiony < thisTransform.position.y)
{
HeroAnimate.Heroindex = 1;
}
transform.position = new Vector3(newPositionx, newPositiony, 0);
// I am getting erros here and my ship sometimes has no renderer enabled at the scene start…WHY?
}
}
the original SmoothFollow2D.js in java was:
var target : Transform;
var smoothTime = 0.3;
private var thisTransform : Transform;
private var velocity : Vector2;
function Start()
{
thisTransform = transform;
}
function Update()
{
thisTransform.position.x = Mathf.SmoothDamp( thisTransform.position.x,
target.position.x, velocity.x, smoothTime);
thisTransform.position.y = Mathf.SmoothDamp( thisTransform.position.y,
target.position.y, velocity.y, smoothTime);
}
I have an invisible sphere that get the touches and my ship just follow it, giving me a moving gravity effect. So…Could someone experienced with changing Java to C sharp give a hand here my developer friends. ![]()