Hopefully this is the last time that I ask about getting help with a script conversion for a week or two :D.
I am converting the Aim Down Sights Script on Unify into C#. (Well Parts of it)
Here is the Java:
var gun : Transform;
static var nextPos = 0.1;
static var nextField = 60.0;
static var nextPos2 = -1.55;
var dampVelocity = 0.4;
var dampVelocity2 = 0.4;
var dampVelocity3 = 0.4;
function Update () {
var newPos = Mathf.SmoothDamp(gun.transform.localPosition.x, nextPos, dampVelocity, .3);
var newField = Mathf.SmoothDamp(Camera.main.fieldOfView, nextField, dampVelocity2, .3);
var newPos2 = Mathf.SmoothDamp(gun.transform.localPosition.y, nextPos2, dampVelocity3, .3);
gun.transform.localPosition.x = newPos;
gun.transform.localPosition.y = newPos2;
Camera.main.fieldOfView = newField;
if (Input.GetButton("Fire2")) {
//adjust viewpoint and gun position
nextField = 55.0;
nextPos = -0.13;
nextPos2 = -1.45;
} else {
//adjust viewpoint and gun position
nextField = 60.0;
nextPos = 0.1;
nextPos2 = -1.55;
}
}
and this is my c# thus far:
using UnityEngine;
using System.Collections;
public class ADS : MonoBehaviour {
public Transform gun;
private float nextPos = 0.1f;
private float nextField = 60.0f;
private float nextPos2 = -1.55f;
private float dampVelocity = 0.4f;
private float dampVelocity2 = 0.4f;
private float dampVelocity3 = 0.4f;
void Update (){
float newPos= Mathf.SmoothDamp(gun.transform.localPosition.x, nextPos, ref dampVelocity, .3f);
float newField= Mathf.SmoothDamp(Camera.main.fieldOfView, nextField, ref dampVelocity2, .3f);
float newPos2= Mathf.SmoothDamp(gun.transform.localPosition.y, nextPos2, ref dampVelocity3, .3f);
gun.transform.localPosition.x = newPos;
gun.transform.localPosition.y = newPos2;
Camera.main.fieldOfView = newField;
if (Input.GetButton("Fire2")) {
//adjust viewpoint and gun position
nextField = 55.0f;
nextPos = -0.13f;
nextPos2 = -1.45f;
} else {
//adjust viewpoint and gun position
nextField = 60.0f;
nextPos = 0.1f;
nextPos2 = -1.55f;
}
}
}
I am getting the error "ADS.cs(18,18): error CS1612: Cannot modify a value type return value of `UnityEngine.Transform.localPosition'. Consider storing the value in a temporary variable"
Unsure on what to do.
Cheers, Aaron Lewis