D
D
Demigodd2017-01-24 12:06:01
Unity
Demigodd, 2017-01-24 12:06:01

How to write condition for Vector3?

For example, if Vector3(1) became Vector3(5), then the value of camerago.orthographicSize (i.e. zoom) smoothly changed to 10.

using UnityEngine;
using System.Collections;

public class Eat : MonoBehaviour
{
  public string Tag;
  public float Increase;
  private static Vector3 newScale = new Vector3 (1,1,1);
  public Camera camerago;
  float zoom = 5;

  void Update()
  {
    transform.localScale = Vector3.Lerp (transform.localScale, newScale, Time.deltaTime * 2);
    camerago.orthographicSize = zoom;

    /*if (newScale == new Vector3 (10,10,10)) 
    {
      zoom = 10 * Time.deltaTime;

    }*/
  }

  void OnTriggerEnter(Collider other)
  {
    if(other.gameObject.tag == Tag)
    {
      newScale = transform.localScale + new Vector3(Increase,Increase,Increase);

      Destroy(other.gameObject);
    }
  }
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Daniil Basmanov, 2017-01-24
@Demigodd

In the same place where you start changing the scale, change the target value of the camera size.

public class Eat : MonoBehaviour
{
    public string Tag;
    public float Increase;
    public Camera camerago;

    private Vector3 newScale = Vector3.one;
    private float newZoom = 5;

    private void Update()
    {
        transform.localScale = Vector3.Lerp(transform.localScale, newScale, Time.deltaTime*2);
        camerago.orthographicSize = Mathf.Lerp(camerago.orthographicSize, newZoom, Time.deltaTime);
    }

    private void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.CompareTag(Tag))
        {
            newScale = transform.localScale + new Vector3(Increase, Increase, Increase);
            newZoom = Increase;

            Destroy(other.gameObject);
        }
    }
}

In general, yes, they advise you correctly, do tutorials, many questions will disappear immediately.
Where to start learning Unity3D?
https://docs.unity3d.com/ScriptReference/Mathf.Ler...
https://docs.unity3d.com/ScriptReference/Component...

G
GavriKos, 2017-01-24
@GavriKos

Well, write like this - if each dimention of the vector is equal to 5, then start a smooth change. The last one is the flag. And then separately check this flag. Or a coroutine inside, but I personally am against this :-)
In general, IMHO it's too early for you to write games yet - you have difficulties with such simple things. Try something faster.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question