Rotation variable problem

I am trying to make a little confetti explosion for my game with the below code. The issue is that while the trans variable does change, that change does not apply to the eulerAngles. So all my confetti shoots out in a straight line. When I set the trans.x/y/z += 5; why does this not apply to the actual eulerAngles? Here is a link to a video of the program in action.  Thanks!




using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Confetti : MonoBehaviour
{


public GameObject confetti, confettiCopy;
public int firePower = 10, inCo;
public Vector3 trans;


void Start()
{
trans = transform.rotation.eulerAngles;
Application.targetFrameRate = 90;
}

void OnTriggerEnter(Collider col)
{

trans.x += 5;
trans.y += 5;
trans.z += 5;

if (col.CompareTag("bullet")){
StartCoroutine(ConfettiShoot());
}
}


IEnumerator ConfettiShoot()
{

for (int z = 90; z > 0; z--)
{
confettiCopy = Instantiate(confetti, transform.position, transform.rotation);
confettiCopy.GetComponent<Rigidbody>().AddRelativeForce(0, 0, firePower, ForceMode.Impulse);
yield return null;
}
}
}


  • Jonathan Gonzalez(jgonzalez) replied

    As far as I know you can't separate the Vector3 in that manner and add separate values. You would have to create a new Vector3 with the additional values. Try this:


    trans = new Vector3(trans.x + 5f, trans.y + 5f, trans.z + 5f);
    


    This should work for adding 5 to each of the X, Y and Z values of trans.