Log in or register to post comments

[HELP] Increase the Scale of model

April 16, 2013 - 10:14am #1

Now how do I make a button (+) and the (-) when pressing the power button (+) to add the model size by my Code is like this.

void OnGUI() {

		if (GUI.Button (new Rect (Screen.width - 100,Screen.height - 70,100,100), zoominpic)) {
			a++;			
			for(int i = 1; i <= a; i++){			
				teapot.transform.localScale = new Vector3(i,i,i);//set your desired local scale her	
			}
		}
		
	}

 

1.Which I would like to know if it will add 0.5 at a time?

2.Or that there are simpler ways to increase the size of this model?

3.If the model is to come back as the same size. Must use the Code?

 

Thanks

[HELP] Increase the Scale of model

September 22, 2017 - 5:01am #14

Show this v.sample video to change scale , size on touch mobile android or iOS

https://youtu.be/Y1LqtleBezc?list=PLazvcyckcBwjSxqwlSr6c2l8FEK-vxSV8

Working on Unity 5.6.x and unity 2017

[HELP] Increase the Scale of model

April 17, 2013 - 11:32pm #13

 

Now I press the button to increase the size, Model, but when I press the button, the Model is missing from the Marker, I just press the button to reduce the size Model.
 
Model shows the same, which is to increase and decrease the size of each is equal to 0.3. 
 
Anyone can help me, one at a time.

 

dorankseo wrote:

This my code:

using System;
using UnityEngine;
using System.Collections;

public class ButtonZoomCap : MonoBehaviour {
	public Texture zoominpic;
	public Texture zoomoutpic;
	public Texture capturepic;
	public float sW;
	public float sH;
	public bool mCap,mZoom;
	private int screenshotCount = 0;
	public GameObject teapot;
	private Vector3 tempScale;
	
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
		if (Input.GetKeyDown(KeyCode.Escape)) 
        { 
            Application.Quit(); 
        }
	}
	
	void OnGUI() {
		if (GUI.Button (new Rect (Screen.width - 100,Screen.height - 70,100,100), zoominpic)) {
			scaleup();
		}	
		if (GUI.Button (new Rect (Screen.width - 200,Screen.height - 70,100,100), zoomoutpic)) {
			scaledown();
		}
		
	}
	
	private void scaleup(){
		teapot.transform.localScale += new Vector3(0.3F, .3F, .3F);	
	}
	
	private void scaledown(){
		teapot.transform.localScale -= new Vector3(0.3F, .3F, .3F);	
	}
}

 

If I press the button "Zoominpic" my Model will expand by 0.3, which is a big no for sure. If the normal size of Model = 1 to plus 0.3 will be equal to 1.3, which is, of course, but my problem is that when I press the button, the Model is missing from the Marker if you press the button "zoomoutpic" Model, it will display the same, and the size is reduced as 1 original.
 
And here is my problem. 
There is a solution?
 
 
Thank you very much

[HELP] Increase the Scale of model

April 17, 2013 - 12:52pm #12

vincekilian wrote:

If possible, please zip your Unity project and post it so we can better assist you.

 

 

How do I attach a file to send in a personal message.
 
 
 
Thanks dude

[HELP] Increase the Scale of model

April 17, 2013 - 12:38pm #11

If possible, please zip your Unity project and post it so we can better assist you.

[HELP] Increase the Scale of model

April 17, 2013 - 11:22am #10

This my code:

using System;
using UnityEngine;
using System.Collections;

public class ButtonZoomCap : MonoBehaviour {
	public Texture zoominpic;
	public Texture zoomoutpic;
	public Texture capturepic;
	public float sW;
	public float sH;
	public bool mCap,mZoom;
	private int screenshotCount = 0;
	public GameObject teapot;
	private Vector3 tempScale;
	
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
		if (Input.GetKeyDown(KeyCode.Escape)) 
        { 
            Application.Quit(); 
        }
	}
	
	void OnGUI() {
		if (GUI.Button (new Rect (Screen.width - 100,Screen.height - 70,100,100), zoominpic)) {
			scaleup();
		}	
		if (GUI.Button (new Rect (Screen.width - 200,Screen.height - 70,100,100), zoomoutpic)) {
			scaledown();
		}
		
	}
	
	private void scaleup(){
		teapot.transform.localScale += new Vector3(0.3F, .3F, .3F);	
	}
	
	private void scaledown(){
		teapot.transform.localScale -= new Vector3(0.3F, .3F, .3F);	
	}
}

 

If I press the button "Zoominpic" my Model will expand by 0.3, which is a big no for sure. If the normal size of Model = 1 to plus 0.3 will be equal to 1.3, which is, of course, but my problem is that when I press the button, the Model is missing from the Marker if you press the button "zoomoutpic" Model, it will display the same, and the size is reduced as 1 original.
 
And here is my problem. 
There is a solution?
 
 
Thank you very much

[HELP] Increase the Scale of model

April 17, 2013 - 11:18am #9

Your scale is relative to the image target (marker) since its a child of the image target.  Therefore, you may be incrementing by a size that is much too large or small after factoring in that its scale value is relative to an image target that usually has a default of 200,200,200 on XYZ for scale.  Check in your scene what the normalized scale is of the object when it is parented to the image target (marker), and then adjust the size manually in the editor to the desired "new" scale, and check the delta between those values.  Odds are that you only need to make minor adjustments to see changes in scale on button press (+ or -), so you could be adjusting the scale too large or too small, effectively causing your object to dissappear from view since its outside the camera's bounds.

[HELP] Increase the Scale of model

April 17, 2013 - 10:48am #8

When I press the button (+), the extended Model, but usually my problem Model is missing from the Marker at problem solving?

[HELP] Increase the Scale of model

April 17, 2013 - 10:41am #7

 

When I press the button to add a Model size has gone from a Marker, but enough to reduce the size of the Model, holding back the same.
 
What Code do I need to add?
 
Help me
 
I'm not sure what you mean by this statement, however to increment the scale, use the += or -= operators to add to the current value.
 
For example:
 
tempScale.x += 0.5f;

...samples the current tempScale and increments it by .5f.  Inversely, decrement the value using -=;

I'd also recommend moving your sW and sH (Screen.width and Screen.height) calculations out of OnGUI() and into the Awake() or Start() methods.  OnGUI() is calculated every frame, so only execute code in the OnGUI() method if absolutely necessary to execute the code every frame (same goes for Update() and LateUpdate() methods).  Moving it to Start or Awake will calculate the value once and cache it, so you wont spend processing cycles recalculating a non-changing value every frame.

 

[HELP] Increase the Scale of model

April 17, 2013 - 8:51am #6

Help me please

[HELP] Increase the Scale of model

April 17, 2013 - 7:19am #5

I have a new problem.

 

Now I can add size and reduce the size of the Model, but I do not want to remove the camera to shine. Marker, Model I, Model based on past by Hierarchy is as follows:

1. AR Camera
2. Directional light
3. ImageTarger
4. teapot

But when I changed to a new Hierarchy is as follows:

1. AR Camera
2. Directional light
3. ImageTarger
-------teapot

 

When I press the button to add a Model size has gone from a Marker, but enough to reduce the size of the Model, holding back the same.
 
What Code do I need to add?
 
Help me
 
My Code ::
using System;
using UnityEngine;
using System.Collections;

public class ButtonZoomCap : MonoBehaviour {
	public Texture zoominpic;
	public Texture zoomoutpic;
	public Texture capturepic;
	public float sW;
	public float sH;
	public bool mCap,mZoom;
	private int screenshotCount = 0;
	public GameObject teapot;
	private Vector3 tempScale;
	// Use this for initialization
	void Start () {
		//teapot = GameObject.Find("teapot");
		tempScale = teapot.transform.localScale;
	}
	
	// Update is called once per frame
	void Update () {
		
		if (Input.GetKeyDown(KeyCode.Escape)) 
        { 
            Application.Quit(); 
        }
		if (mCap == true)
		{		
			string screenshotFilename;
			do
			{
				screenshotCount++;
				screenshotFilename = "screenshot" + screenshotCount + ".png";
			} while (System.IO.File.Exists(screenshotFilename));
			Application.CaptureScreenshot(Application.persistentDataPath + "/mnt/sdcard/" + screenshotFilename);
		}
		
	}
	
	void OnGUI() {
		sW = Screen.width;
		sH = Screen.height;
		mCap = false;
		mZoom = false;
		if (GUI.Button (new Rect (Screen.width - 100,Screen.height - 70,100,100), zoominpic)) {
			tempScale = teapot.transform.localScale;
			float xx = tempScale.x;
			float yy = tempScale.y;
			float zz = tempScale.z;
			tempScale.x = xx + 0.5f;
			tempScale.y = yy+0.5f;
			tempScale.z = zz+0.5f;
			teapot.transform.localScale = tempScale;		
		}	
		if (GUI.Button (new Rect (Screen.width - 200,Screen.height - 70,100,100), zoomoutpic)) {
			float xd = tempScale.x;
			float yd = tempScale.y;
			float zd = tempScale.z;
			tempScale.x = xd - 0.5f;
			tempScale.y = yd -0.5f;
			tempScale.z = zd -0.5f;
			teapot.transform.localScale = tempScale;
		}
		// Capture Screen
		if (GUI.Button (new Rect (Screen.width - 300,Screen.height - 70,100,100), capturepic)) {
			mCap = true;
		}
	}
}

 

 

[HELP] Increase the Scale of model

April 17, 2013 - 2:18am #4

Now I do it all. Thanks dude

[HELP] Increase the Scale of model

April 17, 2013 - 1:40am #3

vincekilian wrote:

In C# you'll probably need to store teapot.transform.localScale in a temporary variable, modify the properties of the temp variable, and then assign the temp variable back to the original localScale.

Vector3 tempScale = teapot.transform.localScale;
tempScale.x = 3.0f;
teapot.transform.localScale = tempScale;

Just a quick example of modifying the X axis scale of the teapot.  I'd also suggest moving your code into its own function, something like ScaleObject() which you could optionally pass axis to affect, amount to scale, etc as arguments.  Allows the code to be reused in other areas as well as keeps your code clean and manageable.

 

Thank you so much to help answer questions in verse 3.

Now, 1 questions remain:

1.Which I would like to know if it will add 0.5 at a time?

[HELP] Increase the Scale of model

April 16, 2013 - 11:41am #2

In C# you'll probably need to store teapot.transform.localScale in a temporary variable, modify the properties of the temp variable, and then assign the temp variable back to the original localScale.

Vector3 tempScale = teapot.transform.localScale;
tempScale.x = 3.0f;
teapot.transform.localScale = tempScale;

Just a quick example of modifying the X axis scale of the teapot.  I'd also suggest moving your code into its own function, something like ScaleObject() which you could optionally pass axis to affect, amount to scale, etc as arguments.  Allows the code to be reused in other areas as well as keeps your code clean and manageable.

Log in or register to post comments