Friday, January 28, 2022

Howo to achieve realistic burning paper effect

 https://forum.unity.com/threads/howo-to-achieve-realistic-burning-paper-effect.247656/



Tomb Raider (see at time 29:30) uses a combination of a dissolve shader, particle effect and heat distortion to give the illusion something is burning off. It's not super realistic, but good enough for games IMO. Maybe it a starting point?

Dissolve Shaders:
https://www.assetstore.unity3d.com/en/#!/search/Dissolve Shader

Heat Distortion:
http://forum.unity3d.com/threads/50132-Heat-Distortion

Particle Effects:
https://www.assetstore.unity3d.com/en/#!/search/fire particle

Wednesday, January 12, 2022

Destructible terrain in Unity

 https://github.com/Ideefixze/DTerrain

Create a RaiseEvent so the webhoock PathEvent

 https://forum.photonengine.com/discussion/11457/create-a-raiseevent-so-the-webhoock-pathevent-will-fire


I have been trying to create an trigger in game that will trigger PathEvent.

I tried this:

byte evCode = 0; // my event 0. could be used as "group units"
byte[] content = new byte[] { 1, 2, 5, 10 }; // e.g. selected unity 1,2,5 and 10
bool reliable = true;
PhotonNetwork.RaiseEvent(evCode, content, reliable, null);

No PathEvent is ever called, not sure if it's supported any more?

RaiseEventOptions raiseEventOptions = new RaiseEventOptions();
raiseEventOptions.ForwardToWebhook = true;
byte evCode = 0; // my event 0. could be used as "group units"
byte[] content = new byte[] { 1, 2, 5, 10 }; // e.g. selected unity 1,2,5 and 10
bool reliable = true;
PhotonNetwork.RaiseEvent(evCode, content, reliable, raiseEventOptions);

Friday, December 31, 2021

Check animator is playing or finshed


https://answers.unity.com/questions/362629/how-can-i-check-if-an-animation-is-being-played-or.html?page=1&pageSize=5&sort=votes


 just send your animation name in CurrentAnimation you want to check.

  1. public IEnumerator CheckAnimationCompleted(string CurrentAnim, Action Oncomplete)
  2. {
  3. while (!Animator.GetCurrentAnimatorStateInfo(0).IsName(CurrentAnim))
  4. yield return null;
  5. if (Oncomplete != null)
  6. Oncomplete();
  7. }

calling coroutine

  1. StartCoroutine(CheckAnimationCompleted("Shoot", () =>
  2. {
  3. Animator.SetBool("Shoot", false);
  4. // Your any code
  5. }
  6. ));

Wednesday, December 1, 2021

Check gameobject is visible on screen

 


Answer by Taylor-Libonati 

Here's the method I used with success:

Convert the position of the object into viewport space. If the viewport space is within 0-1 you are in the cameras frustum. This method also allows you to add a margin amount if you want, so that objects turn on when they are almost in view.

  1. Vector3 screenPoint = playerHead.leftCamera.WorldToViewportPoint(targetPoint.position);
  2. bool onScreen = screenPoint.z > 0 && screenPoint.x > 0 && screenPoint.x < 1 && screenPoint.y > 0 && screenPoint.y < 1;

Instantiate Photon object without using Resources folder

 https://forum.unity.com/threads/solved-photon-instantiating-prefabs-without-putting-them-in-a-resources-folder.293853/


PUN 2 is using a PrefabPool to get a GameObject instance. You can write your own but you can also very easily fill the existing pool of type DefaultPool.

The attached MonoBehaviour has a list of "prefabs", which can be edited in the Inspector. This reference means that the assets don't have to be in the Resources folder. In Start(), the list is used to "fill" the DefaultPool. That's enough.

Code (CSharp):
  1. using UnityEngine;
  2. using System.Collections.Generic;
  3. using Photon.Pun;
  4.  
  5.  
  6. public class PreparePool : MonoBehaviour
  7. {
  8.     public List<GameObject> Prefabs;
  9.  
  10.     void Start ()
  11.     {
  12.         DefaultPool pool = PhotonNetwork.PrefabPool as DefaultPool;
  13.         if (pool != null && this.Prefabs != null)
  14.         {
  15.             foreach (GameObject prefab in this.Prefabs)
  16.             {
  17.                 pool.ResourceCache.Add(prefab.name, prefab);
  18.             }
  19.         }
  20.     }
  21. }

Map circle coord to rectanglar coord

 https://stackoverflow.com/questions/13211595/how-can-i-convert-coordinates-on-a-circle-to-coordinates-on-a-square


See Mapping a Square to a Circle. There's also a nice visualization for the mapping. You get:

xCircle = xSquare * sqrt(1 - 0.5*ySquare^2)
yCircle = ySquare * sqrt(1 - 0.5*xSquare^2)