For some reason i can’t delay the destroy gameobject event here is the code -
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor.Animations;
public class DeathTraps : MonoBehaviour {
public Transform player;
void OnTriggerEnter(Collider other)
{
if( other.gameObject.tag == "Player" )
{
other.gameObject.GetComponent<Animation> ().Play("Death");
Destroy(other.gameObject);
Debug.Log(other.gameObject.name);
}
}
I need the death animation to play before the object is destroyed…
And the rotation i am struggling with a lot here is the script without the rotation -
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class Cell : NetworkBehaviour {
public float Speed;
void Update ()
{
if (!isLocalPlayer)
{
return;
}
// DrawRay ();
Vector3 Target = Camera.main.ScreenToWorldPoint (Input.mousePosition);
Target.z = transform.position.z;
Target.z = transform.rotation.z;
transform.position = Vector3.MoveTowards(transform.position , Target , Speed * Time.deltaTime/transform.localScale.x) ;
}
}
Well, for the first part, you have to delay the call to Destroy based on the length of the animation, right?
I don’t fully understand what you’re trying to do in the second script, but I can see right away that you’re overwriting the position of Target.z with the rotation.z (which not only is pointless to overwrite immediately), but 99.99% positive that you don’t want to use rotation.z at all .
okay, the animation last 1 second i believe so how would i write that? and the second script i’m trying to get the player to rotate/face the direction it’s moving in and forgot to delete rotation.z
You can use a time parameter when you call Destroy:
as for the rotation whats the best way of going about it?
I assume you want the object to turn to the mouse pointer
Vector3 Target = Camera.main.ScreenToWorldPoint (Input.mousePosition);
Vector3 direction = Target - transform.position;
if(!Mathf.Approximately(direction.sqrMagnitude,0))
{
Quaternion look = Quaternion.LookRotation(direction);
transform.rotation = Quaternion.RotateTowards(transform.rotation,look,degreesPerSecond * Time.deltaTime);
}
transform.position = Vector3.MoveTowards(transform.position , Target , Speed *Time.deltaTime) ;
Um, you’d have to create that variable yourself and assign a suitable value 
okay, it still doesn’t rotate the character 
here’s the latest script
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class Cell : MonoBehaviour {
public Camera ourCamera ;
private Vector3 mouselocation ;
public float Speed;
private Vector3 direction ;
private PlayerController RefPlayerController;
void Start ()
{
// if ourCamera is null then set the Main Camera to the variable ourCamera
if (!ourCamera)
{
ourCamera = Camera.main ;
}
if (RefPlayerController == null) {
RefPlayerController = GetComponent<PlayerController> ();
}
}
void Update ()
{
// DrawRay ();
Vector3 Target = Camera.main.ScreenToWorldPoint (Input.mousePosition);
Target.z = transform.position.z;
Target.z = transform.rotation.z;
transform.position = Vector3.MoveTowards(transform.position , Target , Speed * Time.deltaTime/transform.localScale.x) ;
}
}