I am new to unity and programming in general, so excuse me if this is a simple question. I am trying to get a gameobject become twice as large and move to the player’s position once when the player interacts with it. However, whenever it moves the gameobject, it disappears from the game but I can still see it in the scene view. Any help would be appreciated. Below is my code and a screenshot of what I described.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PickupScript : MonoBehaviour {
Transform camerapos;
Transform size;
int scaled = 0;
public GameObject cam;
void Start()
{
size = GetComponent<Transform> ();
camerapos = cam.GetComponent<Transform> ();
}
void OnTriggerEnter2D(Collider2D col) {
if (globalvar.interact) {
if (scaled == 0) {
size.localScale = new Vector2 (2, 2);
size.position = camerapos.position;
scaled = 1;
}
}
}
void OnTriggerStay2D(Collider2D col) {
if (globalvar.interact) {
if (scaled == 0) {
size.localScale = new Vector2 (2, 2);
size.position = camerapos.position;
scaled = 1;
}
}
}
}