Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Freeze Effect C#

Discussion in 'Scripting' started by armorhide406, May 26, 2016.

  1. armorhide406

    armorhide406

    Joined:
    Mar 18, 2016
    Posts:
    16
    How would I go about scripting a freeze effect on an enemy.
    For example, raycasting a spell and hitting an enemy then applying the effect.

    Or something like Dead Space with the stasis field.

    I'm setting up a trigger, but what's the code to use in C# that when the enemy enters they stop moving?
    And then obviously after a certain time via float, I imagine it's just re-enabling whatever I turned off.

    I can supply my code but for now a generic solution would be greatly appreciated.
     
  2. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Just stop moving it. A GameObject does not move unless you tell it too. So stop telling it to move.

    If you are using a rigidbody then you can set it to kinematic to tell the physics system to ignore it.
     
    Last edited: May 26, 2016
    RavenOfCode likes this.
  3. armorhide406

    armorhide406

    Joined:
    Mar 18, 2016
    Posts:
    16
    I suppose I could also stop playing any animations attached?

    Ok, for something more complex, a la Dead Space, how exactly would I go about slowing everything down?
     
  4. RavenOfCode

    RavenOfCode

    Joined:
    Apr 5, 2015
    Posts:
    869
    Have a freeze method on everything and just Freeze() it. Or set the timescale down?
     
  5. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,960
    Yup! If your enemy has an animator that moves with root motion, this:
    Code (CSharp):
    1. animator.speed = 0f;
    would work.
     
    RavenOfCode likes this.