# AddKey

> Add a new key to the curve.

## Definition

* **Type:** Method
* **Namespace:** [UnityEngine](/engine/6000.5/script-reference/unityengine.md)
* **Assembly:** UnityEngine.CoreModule

## AddKey(float, float)

Add a new key to the curve.

```csharp
public int AddKey(float time, float value)
```

### Parameters

**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): The time at which to add the key (horizontal axis in the curve graph).**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): The value for the key (vertical axis in the curve graph).

### Returns

| Type                                                       | Description                                                      |
| ---------------------------------------------------------- | ---------------------------------------------------------------- |
| [int](https://learn.microsoft.com/dotnet/api/system.int32) | The index of the added key, or -1 if the key could not be added. |

### Remarks

Smooth tangents are automatically computed for the key. Returns the index of the added key. If no key could be added because there is already another keyframe at the same time -1 will be returned.

Additional Resources: [AnimationCurve.keys](/engine/6000.5/script-reference/unityengine/animationcurve/keys.md) variable.

## AddKey(Keyframe)

Add a new key to the curve.

```csharp
public int AddKey(Keyframe key)
```

### Parameters

**** (\[Keyframe]\(/engine/6000.5/script-reference/unityengine/keyframe)): The key to add to the curve.

### Returns

| Type                                                       | Description                                                      |
| ---------------------------------------------------------- | ---------------------------------------------------------------- |
| [int](https://learn.microsoft.com/dotnet/api/system.int32) | The index of the added key, or -1 if the key could not be added. |

### Remarks

Returns the index of the added key. If no key could be added because there is already another keyframe at the same time -1 will be returned.

Additional Resources: [AnimationCurve.keys](/engine/6000.5/script-reference/unityengine/animationcurve/keys.md) variable, [Keyframe](/engine/6000.5/script-reference/unityengine/keyframe.md) struct.
