How to multiply gameobject size on collision?,How to increase the size of a gameObject as a multiple using a script for unity 3d?
I have created a small minigame for my 4th project of unity in my life (yes I am a newbie game dev so any help would benefit me greatly) and I'm currently stuck on increasing the gameObject size as a multiple. This is the code I used:
void OnCollisionEnter(Collision collision) { if(collision.gameObject.tag == "RedSlime") { slimeSound.Play(); Destroy(collision.gameObject); transform.localScale = new Vector3(1.5f, 1.5f, 1.0f); } }
and at the transform.localScale instead of creating a new vector3 my goal is to multiply the current gameObject size by 1.1
Any help would be greatly appreciated and thank you for reading my question (and hopefully answering).
Answer by williamzheng2016 · May 03, 2020 at 04:40 PM
Nvm I got it -
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Enlarge : MonoBehaviour
{
Vector3 temp;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
void OnCollisionEnter(Collision collision)
{
if(collision.gameObject.tag == "RedSlime")
{
Destroy(collision.gameObject);
temp = transform.localScale;
temp.x += 1f;
temp.y += 1f;
transform.localScale = temp;
}
}
}
Your answer
Follow this Question
Related Questions
transform.localScale in Coroutine grows exponentially 0 Answers
Moving GameObject a specific distance in the Z direction and back again - regardless of rotation 1 Answer
Need help getting randomly moving particles to head to the nearest of 4 coordinates. 1 Answer
Helicopter Move Local Position,Local Position 1 Answer
LocalScale not working? 4 Answers