In my game I am using one Ball & one Paddle…I am try to move paddle according to movement of ball in game. In paddle I am attached this script.
using UnityEngine;
using System.Collections;
public class PaddleAutoController : MonoBehaviour {
public float speed=6.0f;
Transform ball;
void Update () {
if(GameObject.FindWithTag("ball"))
{
ball =GameObject.FindWithTag("ball").transform;
if(ball.position.y > 0)
{
Vector3 pos = transform.position;
pos.x = Mathf.Lerp(pos.x, ball.position.x, speed * Time.deltaTime);
transform.position = new Vector3(Mathf.Clamp(transform.position.x, -14, 14),20,0);
}
}
}
But it not working…
Regards
kajal