I have been trying to scale the particle System to match different screen sizes, and noticed some odd effects (which i would conclude to be the result of the Camera.main.WolrdPointtoViewPoint)
I attached the following script to the particle system :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BackgroundController : MonoBehaviour {
private float xmin;
private float ymin;
private float xmax;
private float ymax;
// Use this for initialization
void Start () {
ymin = Camera.main.ViewportToWorldPoint(new Vector3(0,0,this.transform.position.z - Camera.main.transform.position.z)).y;
xmin = Camera.main.ViewportToWorldPoint(new Vector3(0,0,this.transform.position.z - Camera.main.transform.position.z)).x;
xmax = Camera.main.ViewportToWorldPoint(new Vector3(1,1,this.transform.position.z - Camera.main.transform.position.z)).x;
ymax = Camera.main.ViewportToWorldPoint(new Vector3(1,1,this.transform.position.z - Camera.main.transform.position.z)).y;
this.transform.position = new Vector3(
(xmin+xmax)/2f
,ymax
,this.transform.position.z);
ParticleSystem ps = this.GetComponent<ParticleSystem>();
Vector3 psBox = new Vector3((Mathf.Abs(xmin)+Mathf.Abs(xmax)/2),1f,1f);
ParticleSystem.ShapeModule pshape = ps.shape;
pshape.box = psBox;
}
// Update is called once per frame
void Update () {
}
}
Everything works fine, but the particle System is not scaled correctly, its not wide enough to fit the whole screen. At the moment I have trouble understanding “WHY” this is happening. Maybe anyone has tried something alike.
I’m using Unity 5.6.1f1.