Question by
wondersilver · Jun 09, 2016 at 05:31 AM ·
2d gameenemy2 playerarcade
how to make an enemy into a second player
i just began useing unity and i made a pong game in the game there is one player and one enemy ai, and i want to know how to make the enemy ai into a second player so it can be a 2 player game. here are the player and enemy scripts just in case you need them
the enemy script
void Update()
{
ballObj = GameObject.FindGameObjectWithTag("Ball");
if(ballObj != null)
{
targetPos = Vector3.Lerp(transform.position, ballObj.transform.position, Time.deltaTime * speed);
playerPos = new Vector3(-20, Mathf.Clamp(targetPos.y, -13, 13), 0);
transform.position = new Vector3(20, playerPos.y, 0);
}
}
the player script
void Update()
{
float yPos = transform.position.y + (Input.GetAxis("Vertical") * paddleSpeed);
playerPos = new Vector3(-20, Mathf.Clamp(yPos, -11, 11), 0);
transform.position = playerPos;
}
Comment