This post contains the code and art from this YouTube video.
Download the sprites from this link: AirHockeyArt
PlayerMovement.cs
using UnityEngine;
public class PlayerMovement : MonoBehaviour {
bool wasJustClicked = true;
bool canMove;
Vector2 playerSize;
// Use this for initialization
void Start () {
playerSize = gameObject.GetComponent<SpriteRenderer>().bounds.extents;
}
// Update is called once per frame
void Update () {
if (Input.GetMouseButton(0))
{
Vector2 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
if (wasJustClicked)
{
wasJustClicked = false;
if ((mousePos.x >= transform.position.x && mousePos.x < transform.position.x + playerSize.x ||
mousePos.x <= transform.position.x && mousePos.x > transform.position.x - playerSize.x) &&
(mousePos.y >= transform.position.y && mousePos.y < transform.position.y + playerSize.y ||
mousePos.y <= transform.position.y && mousePos.y > transform.position.y - playerSize.y))
{
canMove = true;
}
else
{
canMove = false;
}
}
if (canMove)
{
transform.position = mousePos;
}
}
else
{
wasJustClicked = true;
}
}
}

???
if im make my own design and names. it is gonna not working to the coding?
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.
Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me.
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?
my code won’t work with the drag and click system. it worked until I added the RB text
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.