# Why won't this script work?

I have a code that lerps a certain variable in a certain script. Here’s the code…

``````var NormalY: float = 0; // XOffset while not aiming
var AimY: float = 0.2; // XOffset while aiming
private var cameraScript: MouseOrbitOTS;
function Start(){
cameraScript = GetComponent(MouseOrbitOTS);
var ch:Camera = GetComponent(Camera);
}
function Update(){
var cameraY = NormalY;
if (Input.GetButton("Aim")){
cameraY = AimY;
}
cameraScript.yOffset = cameraY; // set XOffset while aiming or not aiming
}
``````

And here’s the script it functions with…

``````var target : Transform;
var distance = 10.0;

var xOffset = 0.0;
var yOffset = 0.0;
var xSpeed = 250.0;
var ySpeed = 120.0;
var yMinLimit = -20;
var yMaxLimit = 80;
var distanceMin = 3;
var distanceMax = 15;
private var x = 0.0;
private var y = 0.0;
function Start () {
var angles = transform.eulerAngles;
x = angles.y;
y = angles.x;
// Make the rigid body not change rotation
if (rigidbody)
rigidbody.freezeRotation = true;
}
function LateUpdate () {
if (target) {
x += Input.GetAxis("Mouse X") * xSpeed * distance* 0.02;
y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02;
y = ClampAngle(y, yMinLimit, yMaxLimit);
var rotation = Quaternion.Euler(y, x, 0);
distance = Mathf.Clamp(distance - Input.GetAxis("Mouse ScrollWheel")*5, distanceMin, distanceMax);
var hit : RaycastHit;
if (Physics.Linecast (target.position, transform.position, hit)) {
distance -=  hit.distance;
}
var position = rotation * Vector3(xOffset, yOffset, -distance) + target.position;
transform.rotation = rotation;
transform.position = position;
}
}
static function ClampAngle (angle : float, min : float, max : float) {
if (angle < -360)
angle += 360;
if (angle > 360)
angle -= 360;
return Mathf.Clamp (angle, min, max);
}
``````

It works fine, but I went to change it so it would function with another script, and I got an error. Here’s the changed version of the first script…

``````var NormalY: float = 0; // XOffset while not aiming
var AimY: float = 0.2; // XOffset while aiming
private var cameraScript: GunSway;
function Start(){
cameraScript = GetComponent(GunSway);
var ch:Camera = GetComponent(Camera);
}
function Update(){
var cameraY = NormalY;
if (Input.GetButton("Fire2")){
cameraY = AimY;
}
cameraScript.defaultPosition.y = cameraY; // set XOffset while aiming or not aiming
}
``````

And here’s the script I want it to work with…

``````using UnityEngine;
using System.Collections;

public class GunSway: MonoBehaviour {
public float moveAmount = 1f;
public float moveSpeed = 2f;
public GameObject gun;
private float moveOnX;
private float moveOnY;
public Vector3 defaultPosition;
public Vector3 newGunPosition;

// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update () {

moveOnX = Input.GetAxis("Mouse X") * Time.deltaTime * moveAmount;

moveOnY = Input.GetAxis("Mouse Y") * Time.deltaTime * moveAmount;

newGunPosition = new Vector3 (defaultPosition.x+moveOnX, defaultPosition.y+moveOnY, defaultPosition.z);

gun.transform.localPosition = Vector3.Lerp(gun.transform.localPosition, newGunPosition, moveSpeed*Time.deltaTime);

}

}
``````

I got this error when I changed the script…

Assets/AimLerpY.js(3,27): BCE0018: The name ‘GunSway’ does not denote a valid type (‘not found’).

Why do I get this if it worked fine with a different script?

Because GunSway is a c# and AimLeryY is a js, you need to make sure the c# compiles first
move it into a folder called ‘plugins’