So i made an augmented reality which can rotate and scale using UI button. Then, i add the script for rotate and scale. But when i want to add component using those script, the only one i can found is rotate. As for scale, turns out there is error comes up : Please help me, this is for my assigment. This is the script i use for scale : using System.Collections; using System.Collections.Generic; using UnityEngine; public class NewBehaviourScript : MonoBehaviour { public GameObject Object; private bool _ZoomIn; private bool _ZoomOut; //object scale speed public float Scale = 0.1f; // Update is called once per frame void Update() { if (_ZoomIn) { //make a bigger object Object.transform.localScale += new Vector3(Scale, Scale, Scale); } if (_ZoomOut) { //make a small object Object.transform.localScale -= new Vector3(Scale, Scale, Scale); } } //Make object scaled big public void OnPressZoomIn() { _ZoomIn = true; } public void OnReleaseZoomIn() { _ZoomIn = false; } //Make object scaled small public void OnPressZoomOut() { _ZoomOut = true; } public void OnReleaseZoomOut() { _ZoomOut = false; }public GameObject Object; private bool _ZoomIn; private bool _ZoomOut; //object scale speed public float Scale = 0.1f; // Update is called once per frame void Update() { if (_ZoomIn) { //make a bigger object Object.transform.localScale += new Vector3(Scale, Scale, Scale); } if (_ZoomOut) { //make a small object Object.transform.localScale -= new Vector3(Scale, Scale, Scale); } } //Make object scaled big public void OnPressZoomIn() { _ZoomIn = true; } public void OnReleaseZoomIn() { _ZoomIn = false; } //Make object scaled small public void OnPressZoomOut() { _ZoomOut = true; } public void OnReleaseZoomOut() { _ZoomOut = false; } }
Does your assignment include understanding basic compiler error messages? The reason I ask is that not only is it telling you that you are defining something called "Object" twice, it even tells you which line so it's practically impossible not to see it which has me confused. If you had used code-tags we'd be able to tell you which line the error messages tells you the problem is on but despite that you can see you've defined "Object" twice. Just looks like you've copy/pasted the code into the same file. Everything is duplicated.
Yes, i'm only copied the script because i don't really know about coding and somehow i need them to complete my assignment . And i just realized too that i double copied the script (i'm sorry), that's why the error comes up. So i fix that problem. But i don't understand, why i can't find the scale script when i want to add component on object even after i fix that?.
The name of the script must match exactly the name of the class. If you had used Unity to create it then this would've been done for you. Filename = "ScaleInOut.cs" Scriptname = "NewBehaviourScript". Should this be "ScaleInOut" ?
Oh my gosh, i just found the answer. So, i deleted the script and made the new one with the same script and the problem solved. I can add the component on my object. I'll try your advice when if i found an error again. Thanks a lot MelvyMay for the help