I don’t know what I did wrong.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Paddle : MonoBehaviour {
// configuration paramaters
[SerializeField] float minX = 1f;
[SerializeField] float maxX = 15f;
[SerializeField] float screenWidthInUnits = 16f;
[SerializeField] float shrink;
private bool small ;
private Vector3 originalscale;
public float timer ;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
float mousePosInUnits = Input.mousePosition.x / Screen.width * screenWidthInUnits;
Vector2 paddlePos = new Vector2(transform.position.x, transform.position.y);
paddlePos.x = Mathf.Clamp(mousePosInUnits, minX, maxX);
transform.position = paddlePos;
}
public void OnTriggerEnter2D(Collider2D collision)
{
if (collision.gameObject.tag.Equals("enemy"))
{
originalscale = transform.localScale -= new Vector3(0.5f, 0, 0);
small = true;
}
if (small==true)
{
timer = 1f;
}
if (small)
{
timer -= Time.deltaTime;
if (timer <= 0)
{
transform.localScale += new Vector3(0.5f, 0, 0);
}
if (transform.localScale == originalscale)
{
small = false;
}
}
}
}