When game starts player is moving right on x axis by this small speed 0.5 , but how to make when game starts again to start to move player randomly on x axis(left or right)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class vvvv : MonoBehaviour {
public float speed = 11.4f;
private float move = 0.5f;
public Rigidbody2D rb;
private float movement = 0f;
static int score = 0;
static int hiScore = 0;
public Text scoreText;
public Text hiScoreText;
static public void AddPoint()
{
score++;
if (score > hiScore)
{
hiScore = score;
}
}
void Start()
{
score = 0;
hiScore = PlayerPrefs.GetInt(“hiScore”, 0);
}
void Update()
{
PlayerPrefs.SetInt(“hiScore”, hiScore);
scoreText.text = “Score:” + score;
hiScoreText.text = “HiScore:” + hiScore;
transform.Translate(move*Time.deltaTime , 0, 0);
// movement = Input.GetAxis(“Horizontal”) * speed;
// Move(Input.GetAxis(“Horizontal”));
}
void FixedUpdate()
{
rb.MovePosition(rb.position + new Vector2(movement * Time.fixedDeltaTime, 0f));
}
void OnCollisionEnter2D(Collision2D other)
{
if (other.gameObject.name == “Ball”)
AddPoint();
}
public void Move(float moveInput)
{
movement = moveInput* speed;
}
}