Should be easy.....
Hi All,
I am writing a simple code, which was working fine up until about an hour ago.
Below is the script and I will explain what is wrong afterwards.
@Header("Fidget Attributes")
var state : boolean;
var scale : float;
private var t : float;
var speed : float;
@Header("Bounce Attributes")
var force : float;
var isGrounded : boolean = true;
@Header("Shift Attributes")
var portalOne : GameObject;
var portalTwo : GameObject;
var portalsPlaced : int;
var keyDown : boolean;
@Header("Global Variables")
var ballController : PlayerBallControl;
var playerController : PlayerController;
function Start ()
{
ballController = GetComponent.<PlayerBallControl>();
playerController = gameObject.FindWithTag("IGG").GetComponent.<PlayerController>();
}
function Update()
{
Fidget();
gameObject.Find("Fidget").transform.localScale = Vector3(scale,scale,scale);
}
function LateUpdate ()
{
if(ballController.goodToGo)
{
if(Input.GetKeyDown(KeyCode.Space))
{
if(playerController.currentPlayer == "Fidget")
{
if(!state || state)
{
state = !state;
t = 0;
}
}//End Fidget
if(isGrounded && playerController.currentPlayer == "Bounce")
{
gameObject.Find("Bounce").GetComponent.<Rigidbody>().velocity.y = 0;
gameObject.Find("Bounce").transform.position.y = gameObject.Find("Bounce").transform.position.y + 0.3;
gameObject.Find("Bounce").GetComponent.<Rigidbody>().AddForce(Vector3.up * force);
isGrounded = false;
}//End Bounce
}//End Spacebar
if(playerController.currentPlayer == "Shift")
{
if(Input.GetKeyDown(KeyCode.Space) && portalsPlaced > 0)
{
if(gameObject.FindWithTag("Portal1"))
{
Destroy(gameObject.FindWithTag("Portal1"));
portalsPlaced--;
}
if(gameObject.FindWithTag("Portal2"))
{
Destroy(gameObject.FindWithTag("Portal2"));
portalsPlaced--;
}
if(GetComponent.<Collider>().enabled == false)
GetComponent.<Collider>().enabled = true;
}
if(Input.GetKeyDown(KeyCode.F))
{
if(portalsPlaced == 0)
{
Instantiate(portalOne,Vector3(gameObject.Find("Shift").transform.position.x,gameObject.Find("Shift").transform.position.y - 0.4,gameObject.Find("Shift").transform.position.z),Quaternion.identity);
keyDown = true;
portalsPlaced ++;
}
else
keyDown = false;
if(portalsPlaced == 1 && !keyDown && !gameObject.FindWithTag("Portal2"))
{
Instantiate(portalTwo,Vector3(gameObject.Find("Shift").transform.position.x,gameObject.Find("Shift").transform.position.y - 0.4,gameObject.Find("Shift").transform.position.z),Quaternion.identity);
portalsPlaced ++;
}
if(portalsPlaced == 1 && !keyDown && gameObject.FindWithTag("Portal2"))
{
Instantiate(portalOne,Vector3(gameObject.Find("Shift").transform.position.x,gameObject.Find("Shift").transform.position.y - 0.4,gameObject.Find("Shift").transform.position.z),Quaternion.identity);
portalsPlaced ++;
}
}
}//End Shift
}
}
function Fidget()
{
if(!state)
{
if(t<1)
t+= Time.deltaTime * speed;
scale = Mathf.Lerp(0.3,1,t);
}
else
{
if(t<1)
t+= Time.deltaTime * speed;
scale = Mathf.Lerp(1,0.3,t);
}
}
function OnCollisionStay(hit:Collision)
{
if(gameObject.name == "Bounce")
{
for (var contact : ContactPoint in hit.contacts)
{
if(hit.gameObject.tag == "Floor" && contact.normal.y > 0.6)
isGrounded = true;
}
}
}
function ClearPortal()
{
portalsPlaced --;
}
Most of this works fine, but you see the only line of code in the Update() Function? It no longer works. all it has to do is find the gameObject names Fidget which it does fine, and transform its local scale based on the variable "scale". But it doesn't!!! The variable scale changes when I hit space bar as it should (It lerps between 0.3 and 1) but the size of my object remains the same and will not change from 0.3 anymore.
Can someone point of the error I have made. I have read the whole script three times now!
Thanks
Steve
Slight update to this, still not working, but look at line 29....
--> += Vector3 works, but =Vector3 does not. Please help!!
The script works, so something else is going on here. I'm thinking the game object is set to static and it's being batched. Other ideas are to check the global time scale and check if there are more than one object Fidget.
Hi Jess,
Thank you for your response, however all things are okay. Fidget is the only one in the scene and it is not static. The Time scale is also okay as it can be controlled just fine.
Your answer
![](https://koobas.hobune.stream/wayback/20220612062613im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Smooth camera to target Y-height 3 Answers
C# Lerping Problem 0 Answers
Player movement 0 Answers
How to Slerp / Lerp Rotation on a Single Axis? 0 Answers
Final position of the camera movement 0 Answers