Hi, I’m pretty new to Unity and C# and am just messing around for fun. I tried to rewrite a script which I’m using to pickup an item, so instead an item I press on changes scale. I’ve tried to run the script but it doesn’t seem to work, here it is:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ChangeSizeScript : MonoBehaviour
{
public GameObject player;
public float clickRange = 5f; //how far the player can pickup the object from
void Update()
{
if (Input.GetKeyDown(KeyCode.Mouse0)) //capture input
{
//perform raycast to check if player is looking at object within pickuprange
RaycastHit hit;
if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit, clickRange))
{
//make sure click tag is attached
if (hit.transform.gameObject.tag == "canClick")
{
//pass in object hit into the ChangeSize function
ChangeSize(hit.transform.gameObject);
}
}
}
}
void ChangeSize(GameObject changesizeObj)
{
changesizeObj.transform.localScale += new Vector3(5, 5, 5); //change size
}
}
Any help would be much appreaciated