Why?
using UnityEngine;
using System.Collections;
public class HillScript1 : MonoBehaviour
{
bool direcright = true;
public float speed = 5.0f;
public float leftpoi = this.transform.position.x - 4;
public float rightpoi = this.transform.position.x;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
if (direcright)
{//x<1.4, x>4
GetComponent<Rigidbody2D>().velocity = new Vector2(-speed, 0);
if (transform.position.x <= leftpoi)
{
direcright = false;
}
}
else {
GetComponent<Rigidbody2D>().velocity = new Vector2(speed, 0);
if (transform.position.x >= rightpoi)
{
direcright = true;
}
}
}
}