Unity Ninja Unity 3D Forum
To have exclusive access to all downloads, recourses and links within this forum, a free registered account is required. Just a heads up Wink
Go down
Posts : 279
Points : 2169
Rep : 58
Join date : 2013-12-16
Age : 17
Location : Boise Idaho United States
View user profile

Scale Geometry With your Keyboard [By BryceCain25]

on Fri May 08, 2015 10:47 pm
In this script, it demonstrates how you can scale geometry when a trigger is activated and you are pressing right or left arrow key..the multiplier variable allows you to scale in ratios..

var MultiplierZ : int;
var ObjectToScale : GameObject;
var MultiplierY : int;
var MultiplierX : int;

//Created By BryceCain25
//the following script is an example and can be used in any project
// ^ remove the following above when pasting in your code
//Rememeber! this is for learning to :P

function OnTriggerEnter () {
if(Input.GetKeyDown(KeyCode.RightArrow)) {
ObjectToScale.transform.localScale += new Vector3(MultiplierZ*1F, 0, 0); //scale the figure On the Z Axis By
//multiplying Multipler * 1, Vector3 just means we are working with a 3D Object instead of Vector 2
//which would be 2D Figures
//use this example to create the rest of the code, make sure that you are using the right Multiplier :)

The // comments allow you to learn a little bit more than copy and paste. Make sure you remember that the two zeros after "MultiplierZ*1F" are integers that use the Z, Y, and X axis. Use a different "IF" statement for each line of code
1) Use a Collider with the "Trigger" boolean checked off
2) Attach script to object with collider trigger
3) Use player input, as soon as you enter the collider you use <-- --> (Left and Right Arrows) to scale, well, depending on how you coded it from the example.
We are all here to learn, so this is a good way to practice! Very Happy
Back to top
Permissions in this forum:
You cannot reply to topics in this forum