Here is my code: using UnityEngine;
using System.Collections;
public class Paddle : MonoBehaviour {
public bool autoPlay = false;
private Ball ball;
void start(){
ball = GameObject.FindObjectOfType<Ball>();
}
void Update () {
if (!autoPlay) {
MoveWithMouse();
} else {
AutoPlay();
}
}
void AutoPlay()
{
Vector3 paddlePos = new Vector3 (0.5f, this.transform.position.y,0f);
Vector3 ballPos = ball.transform.position;
paddlePos.x = Mathf.Clamp(ballPos.x,0.5f,15.5f);
this.transform.position = paddlePos;
}
void MoveWithMouse()
{
Vector3 paddlePos = new Vector3 (0.5f, this.transform.position.y,0f);
float mousePoseInBlocks = Input.mousePosition.x / Screen.width * 16;
paddlePos.x = Mathf.Clamp(mousePoseInBlocks,0.5f,15.5f);
this.transform.position = paddlePos;
}
}
when i start auto play paddle is not moving. how to fix?