Im new to unity i was wondering if this was possible.
1 Answer
1You can accomplish this by working with Unity’s built in collision system.
By checking for either OnTriggerEnter or OnCollisionEnter (depending on what Collider you have attached to the GameObjects), you would scale down the cube on hit from the projectile.
For example, the cube would have the following script attached to it:
using UnityEngine;
public class ScalingCube : MonoBehaviour
{
public float scaleFactor = 0.1f;
void OnCollisionEnter(Collision c)
{
if(c.gameObject.tag == "Projectile")
{
transform.localScale -= Vector3.one * scaleFactor;
}
}
}
and the Projectile would just have a Collider with a Rigidbody, tagged as “Projectile” and could move according to a script you have on it like:
using UnityEngine;
public class Projectile : MonoBehaviour
{
void Update()
{
transform.position += transform.forward * Time.deltaTime;
}
}
Please check out the Unity Tutorials if this doesn’t make sense to you, and you are a beginner to Unity.
These are located here:
http://unity3d.com/learn/tutorials
thank you :)
– PhantomMagic