Reputation: 33
fellow Unitians. I am having problems with my script now. It is saying it doesn't exist at all, when it is right there in the folder on Unity. I don't know how to solve this problem, and I'm getting this error only when I try to add it to an object already in the game. Please help?
using UnityEngine;
using System.Collections;
public class SwordSwing : MonoBehaviour {
private float swingDuration = 0.5f;
private float swingSpeed = 0.22f;
private float swingTimer = 0f;
private bool swinging = false;
private Vector3 startRot;
void Start () {
startRot = transform.eulerAngles;
}
// Update is called once per frame
void Update () {
if (Input.GetMouseButtonDown(0) && !swinging) {
swinging = true;
}
if (swinging) {
swingTimer += Time.deltaTime;
if (swingTimer < (swingDuration / 2)) {
transform.eulerAngles = Vector3.Lerp(startRot, new Vector3(0, 0, 1), swingSpeed);
}
if (swingTimer > (swingDuration / 2)) {
transform.eulerAngles = Vector3.Lerp(transform.eulerAngles, startRot, swingSpeed);
}
if (swingTimer > swingDuration) {
swingTimer = 0f;
swinging = false;
}
}
}
}
Upvotes: 2
Views: 124
Reputation: 15861
Monobehaviours must be in files named for their class name. Your class must be in a file called
SwordSwing.cs
or it won't work.
Upvotes: 4