using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Players : MonoBehaviour
{
public bool player1;
public float speed = 8;
public Rigidbody2D rb;
private float move;
private Vector2 startPos;
void Start()
{
startPos = transform.position;
}
void Update()
{
if (player1)
{
Vector2 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
mousePosition.x = Camera.main.transform.position.x;
transform.position = mousePosition;
}
else
{
move = Input.GetAxisRaw("Vertical");
}
rb.velocity = new Vector2(rb.velocity.x, move * speed);
}
}
private Vector2 startPos;
is vector 2 no vector 3.
I don’t know if you know this but you can do this to change the value of a vector variable :
private Vector2 startPos = new Vector2(x, y);
You replace x and y with the numbers of your choice.
1 Like