I am currently doing a course in software programming and one of my tasks is to create a game. I have found some code online to try to guide me to do what I want to do but it is in Java and i can’t find anything like it in C#. If anybody could help me translate from Java to C# I would be extremely thankful.
Here is the code;
var projectile : Rigidbody;
var chargeTime = -1.0;
function Update ()
{
var position = Input.mousePosition;
var newPosition = Vector3(position.x,position.y,camera.main.transform.position.y- projectile.transform.position.y);
var lastPosition = Camera.main.ScreenToWorldPoint(newPosition);
transform.LookAt(lastPosition);
transform.rotation.x = 0;
transform.rotation.z = 0;
var autoDestroySeconds = 2;
if(Input.GetMouseButtonDown(0))
{
chargeTime = Time.time;
}
if (!Input.GetMouseButton (0) && chargeTime != -1.0)
{
var speed = 5 + 10 * (Time.time - chargeTime);
ray = Camera.mainCamera.ScreenPointToRay (Input.mousePosition);
var hit : RaycastHit;
if (Physics.Raycast (ray, hit))
{
target = hit.point;
}
else
{
target = (ray.origin + ray.direction * 100);
}
direction = target - transform.position;
var instantiatedProjectile : Rigidbody = Instantiate (projectile, transform.position, Quaternion.FromToRotation (Vector3.forward, direction));
instantiatedProjectile.velocity = direction.normalized * speed;
Destroy (instantiatedProjectile, autoDestroySeconds);
chargeTime = -1.0;
}
}