# SCRIPT REFERENCE

### Overview

There are 3 scripts attached to the character object.

<table data-header-hidden><thead><tr><th width="229.5"></th><th></th></tr></thead><tbody><tr><td>Pixel Character       </td><td>Storing object reference inside the character object and character customization.</td></tr><tr><td>Pixel Character Controller</td><td>Controlling movement of the character.</td></tr><tr><td>Pixel Character Input Mouse and Keyboard</td><td>Reading mouse and keyboard input and feed into the Pixel Character Controller script</td></tr></tbody></table>

There are also 2 scripts attached to the `Animator` object inside character. Generally, you don’t need to pay attention to these two scripts.

<table data-header-hidden><thead><tr><th width="230"></th><th></th></tr></thead><tbody><tr><td>Animation Event Receiver</td><td>For receiving animation events.</td></tr><tr><td>Root Motion Receiver</td><td>For receiving root motion from the animation.</td></tr></tbody></table>

### Pixel Character

For storing object reference inside the character object and character customization.

#### Reference Foldout

Contains reference to objects inside the character object.

#### Customization Foldout

Parameters here is mainly for tweaking the character appearance. The customization is mainly done by changing the materials here.  Can be changed both in editor and runtime.

<table data-header-hidden><thead><tr><th width="179.5"></th><th></th></tr></thead><tbody><tr><td>Blink Interval</td><td>The interval range for the character to play an eye blink animation.</td></tr><tr><td> </td><td></td></tr><tr><td>Hat Material</td><td>Material of the character’s hat</td></tr><tr><td>Hair Material</td><td>Material of the character’s hair</td></tr><tr><td>Eye Material</td><td>Material of the character’s eye</td></tr><tr><td>Eye Base Material</td><td><p>Material of the character’s eye shape.</p><p>You only need to change this when changing the character’s gender.</p></td></tr><tr><td>Facewear Material</td><td>Material of the character’s facewear.</td></tr><tr><td>Cloth Material</td><td>Material of the character’s cloth.</td></tr><tr><td>Pants Material</td><td>Material of the character’s pants.</td></tr><tr><td>Socks Material</td><td>Material of the character’s socks.</td></tr><tr><td>Shoes Material</td><td><p>Material of the character’s shoes.</p><p>This will be displayed behind the character’s pants.</p></td></tr><tr><td>Back Material</td><td>Material of the object the character carries on the back.</td></tr><tr><td>Body Material</td><td><p>Material of the character’s body.</p><p>You need to change this when changing the character’s gender.</p><p>Also, special character presets would use their specific body material, like Vampire or Zombie.</p></td></tr><tr><td> </td><td></td></tr><tr><td>Clip Hair</td><td><p>Hide part of the character’s hair.</p><p>When wearing certain hats, you need to enable this.</p></td></tr><tr><td>Hide Hair</td><td>Completely hide the character’s hair.</td></tr><tr><td>Shoes in Front</td><td>Whether to display shoes in front of the character’s pants.</td></tr></tbody></table>

#### Runtime Foldout

Parameters here should only be changed at runtime except `Facing`.

<table data-header-hidden><thead><tr><th width="179.5"></th><th></th></tr></thead><tbody><tr><td>Facing</td><td><p>The character’s facing.</p><p>Can be changed in editor to set the character’s initial facing.</p></td></tr><tr><td>Alpha</td><td>Controls the transparency of the entire character.</td></tr><tr><td>Is Dead</td><td><p>Whether the character is dead.</p><p>Turning this on will only make the character appear dead on the graphic side. For making the character truly dead, turn on the <code>Is Dead</code> on the <code>Pixel Character Controller</code> script.</p></td></tr><tr><td>Expression</td><td>The character’s expression.</td></tr><tr><td>Injured Front</td><td>Play <code>Injured Front</code> animation.</td></tr><tr><td>Inj<em>ured</em> Back</td><td>Play <code>Injured Back</code> animation.</td></tr><tr><td>Detach Weapon</td><td><p>Detach weapon to a separated object from the character.</p><p>Returns the detached weapon game object.</p></td></tr><tr><td>Clear Weapon</td><td>Clear out everything in the weapon slot.</td></tr></tbody></table>

### Pixel Character Controller

Script for controlling the character’s movement.

It will modify some of the `Facing` parameters in the `Pixel Character` script and parameters in the `Animator` to control animation.

#### **Movement Foldout**

Parameters for the character’s movement.

<table data-header-hidden><thead><tr><th width="230"></th><th></th></tr></thead><tbody><tr><td><em>Gr</em>ound Check Layer Mask</td><td>Objects under this layer mask will be consider ground the character can stand on.</td></tr><tr><td> </td><td></td></tr><tr><td>Walks Speed M<em>ax</em></td><td>Max walking speed.</td></tr><tr><td>Walks Ac<em>c</em></td><td>Walking Acceleration.</td></tr><tr><td> </td><td></td></tr><tr><td>Run Speed Max</td><td>Max running speed.</td></tr><tr><td>Run <em>Ac</em>c</td><td>Running Acceleration.</td></tr><tr><td> </td><td></td></tr><tr><td>Crouch Speed Max</td><td>Max move speed while crouching.</td></tr><tr><td>Crouch Acc</td><td>Crouching acceleration.</td></tr><tr><td> </td><td></td></tr><tr><td>Crawl Speed Max</td><td>Max move speed while crawling.</td></tr><tr><td>Crawl Acc</td><td>Crawling acceleration.</td></tr><tr><td> </td><td></td></tr><tr><td>Air Speed Ma<em>x</em></td><td>Max move speed while in air</td></tr><tr><td>Air Acc</td><td>Air acceleration</td></tr><tr><td> </td><td></td></tr><tr><td>Ground Drag</td><td>Braking acceleration (from movement to still) while on ground</td></tr><tr><td>Air Drag</td><td>Braking acceleration (from movement to still) while in air</td></tr><tr><td> </td><td></td></tr><tr><td>Jump Enabled</td><td>Whether the character can jump.</td></tr><tr><td>Jump Speed</td><td>Speed applied to the character when jump.</td></tr><tr><td>Jump Cooldown</td><td>Time needed to be able to jump again after landing.</td></tr><tr><td>Jump Tolerance</td><td>When character is off ground and inside this time, the character is still able to jump.</td></tr><tr><td>Jump Gravity Multiplier</td><td><p>Gravity multiplier when character is jumping.</p><p>Should be within <code>[0.0,1.0]</code>, set it to lower value so that the longer you press the jump button, the higher the character can jump.</p></td></tr><tr><td>Fall Gravity Multiplier</td><td><p>Gravity multiplier when character is falling.</p><p>Should be equal or greater than <code>1.0</code></p></td></tr><tr><td> </td><td></td></tr><tr><td>Dash Enabled</td><td>Whether the character can dash.</td></tr><tr><td>Dash Spe<em>ed Start</em></td><td>Speed when dash starts.</td></tr><tr><td>Dash Speed Max</td><td>Max move speed while dashing.</td></tr><tr><td>Dash Acc</td><td>Dash acceleration.</td></tr><tr><td>Dash Time</td><td>Time the dash state will last.</td></tr><tr><td>Dash Cooldown</td><td>Time it takes for the character to be able to dash again after exiting dash state.</td></tr><tr><td> </td><td></td></tr><tr><td>Dodge Enabled</td><td>Whether the character can dodge.</td></tr><tr><td>Dodge Speed Mul</td><td>Dodge speed multiplier</td></tr><tr><td>Dodg<em>e</em> Cooldown</td><td>Time it takes for the character to be able to dodge again after exiting dodge state.</td></tr><tr><td> </td><td></td></tr><tr><td>Swim Enabled</td><td><p>Whether the character can swim.</p><p>When disabled the character will ignore the water.</p></td></tr><tr><td>Swim Speed Max</td><td>Max swimming speed.</td></tr><tr><td>Swim Speed Fast Max</td><td>Max swimming speed when in fast moving mode (when the run key is down).</td></tr><tr><td>Swim Acc</td><td>Swim acceleration.</td></tr><tr><td>Swim Buoyancy Speed</td><td>The speed applied to the character as buoyancy when in water.</td></tr><tr><td>Keep in Water Depth When Diving</td><td><p>Whether to automatically keep current in water depth when diving.</p><p>When disabled the character will always try to float to the water surface.</p></td></tr><tr><td></td><td></td></tr><tr><td>Ladder Climb Enabled</td><td>Whether the character can climb ladder.</td></tr><tr><td>Ladder Climb Speed</td><td>Ladder climbing speed.</td></tr><tr><td>Ladder Climb Speed Fast</td><td>Ladder climbing speed when the run key (by default is <kbd>SHIFT</kbd>) is pressed.</td></tr><tr><td> </td><td></td></tr><tr><td>Ledge Climb Enabled</td><td>Whether the character can climb ledge.</td></tr></tbody></table>

#### Attack Foldout

Parameters for the character’s attack action.

<table data-header-hidden><thead><tr><th width="229.5"></th><th></th></tr></thead><tbody><tr><td>Attack Action</td><td>Attack action to perform whether primary attack key (by default is <kbd>LMB</kbd>) is pressed.</td></tr><tr><td>Attack Action Melee</td><td>Attack action to perform whether melee attack key (by default is <kbd>V</kbd>) is pressed, or when the character is in a state when primary attack action is not available, like when crawling or climbing ladder.</td></tr><tr><td> </td><td></td></tr><tr><td>Attack Speed Mul</td><td><p>Speed multiplier of the attack animation.</p><p>You can use this to make the character attack quicker or slower. Default value is <code>1.0</code></p></td></tr><tr><td>Attack Cooldown</td><td><p>Time needed to be able to attack again after last attack action ended.</p><p>Default value is <code>0.0</code>, means no cooldown.</p></td></tr><tr><td> </td><td></td></tr><tr><td>Throw Force</td><td><p>When using <code>Throw</code> attack action, the character will throw out the weapon it is holding.</p><p>This defines the force applied to the thrown weapon.</p></td></tr><tr><td>Throw Angular Speed</td><td>The angular speed applied to the thrown weapon.</td></tr><tr><td> </td><td></td></tr><tr><td>Projectile Speed</td><td>The speed applied the projectile when using <code>Cast</code> or <code>Archery</code> attack action.</td></tr><tr><td>Projectile Prefab</td><td>The prefab of the projectile to be instantiate when using <code>Cast</code> or <code>Archery</code> attack action.</td></tr></tbody></table>

#### Event Foldout

This foldout contains some Unity events that you can use to trigger your own function.

A typical use case is to play sound effects when curtain event happens.

<table data-header-hidden><thead><tr><th width="229.5"></th><th></th></tr></thead><tbody><tr><td>On Footstep</td><td>When the character’s foot touches the ground in animation like walk or run.</td></tr><tr><td> </td><td></td></tr><tr><td>On Jump</td><td>When the character jump away from ground.</td></tr><tr><td><em>On</em> Land</td><td>When the character land on the ground from air.</td></tr><tr><td> </td><td></td></tr><tr><td><em>On</em> Dodge Start</td><td>When dodge action starts.</td></tr><tr><td><em>On</em> Dodge End</td><td>When dodge action ends.</td></tr><tr><td> </td><td></td></tr><tr><td>On Attack Start</td><td>When attack action starts.</td></tr><tr><td>On Attack Hit</td><td>When attack action is supposed to hit the target. Damage to the target can be applied at this event.</td></tr><tr><td>On Attack End</td><td>When attack action ends</td></tr><tr><td> </td><td> </td></tr><tr><td>On Bow Pull</td><td>When using <code>Archery</code> attack action, the character start pulling the bow string.</td></tr><tr><td>On Bow Shoot</td><td>When using <code>Archery</code> attack action, the character release the bow string and the arrow is shot.</td></tr><tr><td> </td><td></td></tr><tr><td>On Throw</td><td>When using <code>Throw</code> attack action, the character throws out the holding weapon.</td></tr></tbody></table>

#### Input Foldout

Parameters for receiving inputs from input scripts.

If you are going to use your own input scripts, you need to modify these parameters in your scripts.

Only available at runtime.

<table data-header-hidden><thead><tr><th width="229.5"></th><th></th></tr></thead><tbody><tr><td>Input Move</td><td>movement input, x for horizontal, y for vertical, x and y should be in <code>[-1.0, 1.0]</code></td></tr><tr><td>Input Run</td><td>Run input, when enabled the character will run instead of walk.</td></tr><tr><td>Input Dash</td><td>Dash input, when triggered the character will enter dash state.</td></tr><tr><td>Input Dodge</td><td>Dodge input, when triggered the character will enter dodge state.</td></tr><tr><td>Input Crouch</td><td>Crouch input, when enabled the character will be crouching.</td></tr><tr><td>Input Crawl</td><td>Crawl input, when enabled the character will be crawling. Will override crouch input.</td></tr><tr><td>Input jump</td><td><p>Jump input, when triggered the character will start to jump.</p><p>When continuously enabled the character will jump higher.</p></td></tr><tr><td>Input Attack</td><td>Primary attack input, will trigger the attack action when available.</td></tr><tr><td>Input Melee</td><td>Melee attack input, will trigger the melee attack action.</td></tr><tr><td>Input Look</td><td>Look input, when enabled the character will look at the position defined by <code>Input Target</code></td></tr><tr><td>Input Target</td><td>This is a world space <code>Vector2</code> position that defines the target the character should look at or point at when performing curtain attack action.</td></tr></tbody></table>

#### Debug Foldout

Parameters for switching debug gizmos display.

#### Runtime Foldout

Parameters here should only be changed at runtime.

Most parameters here is read only and just for exposing states of the controller.

### Pixel Character Input Mouse and Keyboard

This script will read mouse and keyboard input and modify parameters in the `Input` foldout of the `Pixel Character Controller` script.

If you are going to use your own input script or let an AI to control the character, just remove this script.

It is also a good example for showing how to feed input to the `Pixel Character Controller` script.

| *Is Dead* | Is the character dead? if yes, plays dead animation and disable control. |
| --------- | ------------------------------------------------------------------------ |
