Make object move back and forth

Hello fellow unity users. I know this question has been asked, but I cannot get any of the solutions to work for my application. I get a “compiler error: unable to start play mode” error every time I try so start the game. I am trying to get an enemy to move left and right in a loop, Here’s what I have…any help appreciated…

using UnityEngine;
using System.Collections;

public class Oscillate : MonoBehaviour
{
int maxValue = 25;
int minValue = -25;
int currentValue = 0;
int direction = 1;

void Update ()
{
	currentValue += Time.deltaTime * direction;

	if (currentValue >= maxValue) {
		direction *= -1;
		currentValue = maxValue;
	} else if (currentValue <= minValue) {
		direction *= -1;
		currentValue = minValue;
	}

}
	transform.position = new Vector3(currentValue, 0, 0);

}

I think your problem is that Time.deltaTime is a float and currentValue is an Int. You can not implicitly convert a float to an int. You need to change your int currentValue to a float?

Why not use a naturally oscillating function instead of manually hacking it?

using UnityEngine;
using System.Collections;

public class OccilatingPosition : MonoBehaviour
{
    public enum OccilationFuntion { Sine, Cosine }

    public void Start ()
    {
        //to start at zero
        StartCoroutine (Oscillate (OccilationFuntion.Sine, 1f));
        //to start at scalar value
        //StartCoroutine (Oscillate (OccilationFuntion.Cosine, 1f));
    }

    private IEnumerator Oscillate (OccilationFuntion method, float scalar)
    {
        while (true)
        {
            if (method == OccilationFuntion.Sine)
            {
                transform.position = new Vector3 (Mathf.Sin (Time.time) * scalar, 0, 0);
            }
            else if (method == OccilationFuntion.Cosine)
            {
                transform.position = new Vector3(Mathf.Cos(Time.time) * scalar, 0, 0);
            }
            yield return new WaitForEndOfFrame ();
        }
    }
}