Why does my mesh move in game mode?

hello,

i recently purchased an asset from the asset store for a “Simple Door” effect. everything seems fine while editing the scene although when i go into game mode to test it all out, the mesh collider on the door moves to the right causing the door to no longer become a collider. i have emailed the creator of the asset for help but have no response. if someone could see why I’m having this issue, that would be great.

Script below, sorry there is so much!

Thanks,

using UnityEngine;
using System.Collections;

public class SimpleDoor : MonoBehaviour {

//Common Variables
public enum PublicDoorTypeEnum { Swing, Slide }
public PublicDoorTypeEnum PublicDoorType;

private enum DoorTypeEnum { Swing, Slide }
private DoorTypeEnum DoorType;

public enum InitialStateEnum { Open, Closed }
public InitialStateEnum InitialState;

public enum PublicActionSideEnum { Rigth, Left, Up, Down }
public PublicActionSideEnum PublicActionSide;

private enum ActionSideEnum { Rigth, Left, Up, Down }
private ActionSideEnum ActionSide;

public float Speed;
private Mesh doorMesh;
private bool isOpen;
private bool completedAction;
private float toggleFiredTime;
private GameObject Parent;
private enum FlatAxisEnum { X, Z }
private FlatAxisEnum FlatAxis;
private bool keyIsValid;

//Swing Style Variables
public float DesiredRotation;
private float InitialRotation;
private bool pivotChanged;

//Slide Style Variables
public float DesiredSlideLength;
private Vector3 targetPosition;
private Vector3 initialPosition;

//Activation Style Variables
public enum ActivationTypeEnum { Custom, Proximity, ProximityAndInput }
public ActivationTypeEnum ActivationType;

public enum PlayerRecognitionEnum { Tag, GameObj }
public PlayerRecognitionEnum PlayerRecognition;

public string PlayerTag;
public GameObject PlayerObj;
public string PublicInputKey;
private string InputKey;
public float ProximityRadius;
private SphereCollider proximityTrigger;
private bool isOnTriggerArea;


void Awake () 
{
	keyIsValid = true;

	InputKey = PublicInputKey;
	DoorType = (DoorTypeEnum)PublicDoorType;
	ActionSide = (ActionSideEnum)PublicActionSide;

	isOnTriggerArea = false;

	if (InitialState == InitialStateEnum.Open)
		isOpen = true;
	else
		isOpen = false;
}

void Start()
{
	if(ActivationType == ActivationTypeEnum.ProximityAndInput)
	{
		try
		{
			Input.GetKey(InputKey);
		}
		catch (System.Exception e)
		{
			keyIsValid = false;
			Debug.LogException(e, this);
			Debug.LogError("SimpleDoor Script ERROR - The Input Key is invalid, exit play mode and enter a valid Key Code.");
		}
	}

	if(Speed <= 0)
	{
		Debug.LogWarning("SimpleDoor Script WARNING - The Speed of Action seems to be 0 or negative, be aware that the door won't work on these conditions.");
	}

	if (DoorType == DoorTypeEnum.Swing && DesiredRotation == 0)
	{
		Debug.LogWarning("SimpleDoor Script WARNING - The Amount of Rotation seems to be 0, did you forgot to put a value?");
	}
	else if (DoorType == DoorTypeEnum.Slide && DesiredSlideLength == 0)
	{
		Debug.LogWarning("SimpleDoor Script WARNING - The Amount of Slide seems to be 0, did you forgot to put a value?");
	}

	if((ActivationType == ActivationTypeEnum.Proximity || ActivationType == ActivationTypeEnum.ProximityAndInput) && ProximityRadius <= 0)
	{
		Debug.LogWarning("SimpleDoor Script WARNING - The Proximity Radius is 0 or negative, choose a higher number if you want to use the proximity detection.");
	}

	if((ActivationType == ActivationTypeEnum.Proximity || ActivationType == ActivationTypeEnum.ProximityAndInput) && PlayerRecognition == PlayerRecognitionEnum.GameObj && PlayerObj == null)
	{
		Debug.LogError("SimpleDoor Script ERROR - The Player Object of the Type of Player Recognition parameter is null, did you forgot to assign one? This type of Player Recognition won't work without one.");
	}

	if(PlayerTag == "" && (ActivationType == ActivationTypeEnum.Proximity || ActivationType == ActivationTypeEnum.ProximityAndInput) && PlayerRecognition == PlayerRecognitionEnum.Tag)
	{
		Debug.LogWarning("SimpleDoor Script WARNING - The Object Tag is empty, if you wanna identify an untagged object then type Untagged.");
	}

	if(ActivationType == ActivationTypeEnum.Proximity || ActivationType == ActivationTypeEnum.ProximityAndInput)
	{
		proximityTrigger = (SphereCollider)gameObject.AddComponent<SphereCollider>();

		proximityTrigger.isTrigger = true;
		proximityTrigger.radius = ProximityRadius;
	}

	MeshFilter doorMeshFilter = (MeshFilter)gameObject.GetComponent("MeshFilter");
	doorMesh = doorMeshFilter.mesh;

	if(doorMesh.bounds.size.x*transform.localScale.x >= doorMesh.bounds.size.z*transform.localScale.z)
	{
		FlatAxis = FlatAxisEnum.X;
	}
	else
	{
		FlatAxis = FlatAxisEnum.Z;
	}
	
	if(DoorType == DoorTypeEnum.Swing)
	{
		Parent = new GameObject ();
		Parent.name = "Door Hinge";
		var pos = new Vector3 (0, 0, 0);
		
		if(FlatAxis == FlatAxisEnum.X)
		{
			if (ActionSide == ActionSideEnum.Left) {
				DesiredRotation *= -1;
				pos.x += (doorMesh.bounds.size.x) / 2;
			} else if (ActionSide == ActionSideEnum.Rigth) {
				DesiredRotation *= 1;
				pos.x -= (doorMesh.bounds.size.x) / 2;
			}
		}
		else
		{
			if (ActionSide == ActionSideEnum.Left) {
				DesiredRotation *= -1;
				pos.z += (doorMesh.bounds.size.z) / 2;
			} else if (ActionSide == ActionSideEnum.Rigth) {
				DesiredRotation *= 1;
				pos.z -= (doorMesh.bounds.size.z) / 2;
			}
		}
		
		if (ActionSide == ActionSideEnum.Up)
		{
			DesiredRotation *= -1;
			pos.y -= (doorMesh.bounds.size.y) / 2;
		}
		else if (ActionSide == ActionSideEnum.Down)
		{
			DesiredRotation *= 1;
			pos.y += (doorMesh.bounds.size.y) / 2;
		}
		
		Vector3[] verts = doorMesh.vertices; 
		for (int i=0; i<verts.Length; i++) {
			verts  *+= pos;*
  •   	}*
    
  •   	doorMesh.vertices = verts;*
    
  •   	doorMesh.RecalculateBounds ();*
    
  •   	Parent.transform.position = transform.position;*
    
  •   	Parent.transform.rotation = transform.rotation;*
    
  •   	if(transform.parent)*
    
  •   		Parent.transform.parent = transform.parent;*
    
  •   	transform.parent = Parent.transform;*
    
  •   	var local = transform.localPosition;*
    
  •   	if(FlatAxis == FlatAxisEnum.X)*
    
  •   	{*
    
  •   		if (ActionSide == ActionSideEnum.Left) {*
    

_ local.x -= (doorMesh.bounds.size.x / 2) * transform.localScale.x;_

  •   		} else if (ActionSide == ActionSideEnum.Rigth) {*
    

_ local.x += (doorMesh.bounds.size.x / 2) * transform.localScale.x;_

  •   		}*
    
  •   	}*
    
  •   	else*
    
  •   	{*
    
  •   		if (ActionSide == ActionSideEnum.Left) {*
    

_ local.z -= (doorMesh.bounds.size.z / 2) * transform.localScale.z;_

  •   		} else if (ActionSide == ActionSideEnum.Rigth) {*
    

_ local.z += (doorMesh.bounds.size.z / 2) * transform.localScale.z;_

  •   		}*
    
  •   	}*
    
  •   	if (ActionSide == ActionSideEnum.Up)*
    
  •   	{*
    

_ local.y += (doorMesh.bounds.size.y) / 2 * transform.localScale.y;_

  •   	}*
    
  •   	else if (ActionSide == ActionSideEnum.Down)*
    
  •   	{*
    

_ local.y -= (doorMesh.bounds.size.y) / 2 * transform.localScale.y;_

  •   	}*
    
  •   	transform.localPosition = local;*
    
  •   	Collider col = gameObject.GetComponent<Collider>();*
    
  •   	if (col) {*
    
  •   		if (col is BoxCollider) {*
    
  •   			((BoxCollider)col).center += pos;*
    
  •   		} else if (col is CapsuleCollider) {*
    
  •   			((CapsuleCollider)col).center += pos;*
    
  •   		} else if (col is SphereCollider) {*
    
  •   			((SphereCollider)col).center += pos;*
    
  •   		}*
    
  •   	}*
    
  •   	InitialRotation = 0;*
    
  •   }*
    
  •   else if(DoorType == DoorTypeEnum.Slide)*
    
  •   {*
    
  •   	Parent = new GameObject ();*
    
  •   	Parent.name = "Door Slide";*
    
  •   	Parent.transform.position = transform.position;*
    
  •   	if(transform.parent)*
    
  •   		Parent.transform.parent = transform.parent;*
    
  •   	transform.parent = Parent.transform;*
    
  •   	if(ActionSide == ActionSideEnum.Left)*
    

_ DesiredSlideLength*=-1;_

  •   	else if (ActionSide == ActionSideEnum.Rigth)*
    

_ DesiredSlideLength*=1;_

  •   	else if(ActionSide == ActionSideEnum.Up)*
    

_ DesiredSlideLength*=1;_

  •   	else if (ActionSide == ActionSideEnum.Down)*
    

_ DesiredSlideLength*=-1;_

  •   	initialPosition = transform.localPosition;*
    
  •   	if(ActionSide == ActionSideEnum.Left || ActionSide == ActionSideEnum.Rigth)*
    
  •   	{*
    
  •   		if (FlatAxis == FlatAxisEnum.X)*
    

_ targetPosition = transform.localPosition + transform.right * DesiredSlideLength;_

  •   		else if (FlatAxis == FlatAxisEnum.Z)*
    

_ targetPosition = transform.localPosition + transform.forward * DesiredSlideLength;_

  •   	}*
    
  •   	else if(ActionSide == ActionSideEnum.Up || ActionSide == ActionSideEnum.Down)*
    
  •   	{*
    

_ targetPosition = transform.localPosition + transform.up * DesiredSlideLength;_

  •   	}*
    
  •   }*
    
  •   completedAction = true;*
    
  • }*

  • // Update is called once per frame*

  • void Update () {*

  •   if(ActivationType == ActivationTypeEnum.ProximityAndInput && keyIsValid)*
    
  •   {*
    
  •   	if (Input.GetKeyDown(InputKey) && isOnTriggerArea)* 
    
  •   	{*
    
  •   		ToggleDoor();*
    
  •   	}*
    
  •   }*
    
  •   if (DoorType == DoorTypeEnum.Swing)* 
    
  •   {*
    
  •   	completedAction = true;*
    
  •   	if(ActionSide == ActionSideEnum.Left || ActionSide == ActionSideEnum.Rigth)*
    
  •   	{*
    
  •   		if (!isOpen && InitialState == InitialStateEnum.Open && transform.eulerAngles.y != DesiredRotation)* 
    
  •   		{*
    
  •   			transform.localRotation =*
    

_ Quaternion.Lerp (transform.localRotation, Quaternion.Euler (0, DesiredRotation, 0), (Time.time - toggleFiredTime) * Speed);_

  •   			completedAction = false;*
    
  •   		}* 
    
  •   		else if (isOpen && InitialState == InitialStateEnum.Closed && transform.eulerAngles.y != DesiredRotation)* 
    
  •   		{*
    
  •   			transform.localRotation =*
    

_ Quaternion.Lerp (transform.localRotation, Quaternion.Euler (0, DesiredRotation, 0), (Time.time - toggleFiredTime) * Speed);_

  •   			completedAction = false;*
    
  •   		}*
    
  •   		else if (!isOpen && InitialState == InitialStateEnum.Closed && transform.eulerAngles.y != InitialRotation)*
    
  •   		{*
    
  •   			transform.localRotation =*
    

_ Quaternion.Lerp (transform.localRotation, Quaternion.Euler (0, InitialRotation, 0), (Time.time - toggleFiredTime) * Speed);_

  •   			completedAction = false;*
    
  •   		}*
    
  •   		else if (isOpen && InitialState == InitialStateEnum.Open && transform.eulerAngles.y != InitialRotation)*
    
  •   		{*
    
  •   			transform.localRotation =*
    

_ Quaternion.Lerp (transform.localRotation, Quaternion.Euler (0, InitialRotation, 0), (Time.time - toggleFiredTime) * Speed);_

  •   			completedAction = false;*
    
  •   		}*
    
  •   	}*
    
  •   	else if(ActionSide == ActionSideEnum.Up || ActionSide == ActionSideEnum.Down)*
    
  •   	{*
    
  •   		if(FlatAxis == FlatAxisEnum.X)*
    
  •   		{*
    
  •   			if (!isOpen && InitialState == InitialStateEnum.Open && transform.eulerAngles.x != DesiredRotation)* 
    
  •   			{*
    
  •   				transform.localRotation =*
    

_ Quaternion.Lerp (transform.localRotation, Quaternion.Euler (DesiredRotation, 0, 0), (Time.time - toggleFiredTime) * Speed);_

  •   				completedAction = false;*
    
  •   			}* 
    
  •   			else if (isOpen && InitialState == InitialStateEnum.Closed && transform.eulerAngles.x != DesiredRotation)* 
    
  •   			{*
    
  •   				transform.localRotation =*
    

_ Quaternion.Lerp (transform.localRotation, Quaternion.Euler (DesiredRotation, 0, 0), (Time.time - toggleFiredTime) * Speed);_

  •   				completedAction = false;*
    
  •   			}*
    
  •   			else if (!isOpen && InitialState == InitialStateEnum.Closed && transform.eulerAngles.x != InitialRotation)*
    
  •   			{*
    
  •   				transform.localRotation =*
    

_ Quaternion.Lerp (transform.localRotation, Quaternion.Euler (InitialRotation, 0, 0), (Time.time - toggleFiredTime) * Speed);_

  •   				completedAction = false;*
    
  •   			}*
    
  •   			else if (isOpen && InitialState == InitialStateEnum.Open && transform.eulerAngles.x != InitialRotation)*
    
  •   			{*
    
  •   				transform.localRotation =*
    

_ Quaternion.Lerp (transform.localRotation, Quaternion.Euler (InitialRotation, 0, 0), (Time.time - toggleFiredTime) * Speed);_

  •   				completedAction = false;*
    
  •   			}*
    
  •   		}*
    
  •   		else if(FlatAxis == FlatAxisEnum.Z)*
    
  •   		{*
    
  •   			if (!isOpen && InitialState == InitialStateEnum.Open && transform.eulerAngles.z != DesiredRotation)* 
    
  •   			{*
    
  •   				transform.localRotation =*
    

_ Quaternion.Lerp (transform.localRotation, Quaternion.Euler (0, 0, DesiredRotation), (Time.time - toggleFiredTime) * Speed);_

  •   				completedAction = false;*
    
  •   			}* 
    
  •   			else if (isOpen && InitialState == InitialStateEnum.Closed && transform.eulerAngles.z != DesiredRotation)* 
    
  •   			{*
    
  •   				transform.localRotation =*
    

_ Quaternion.Lerp (transform.localRotation, Quaternion.Euler (0, 0, DesiredRotation), (Time.time - toggleFiredTime) * Speed);_

  •   				completedAction = false;*
    
  •   			}*
    
  •   			else if (!isOpen && InitialState == InitialStateEnum.Closed && transform.eulerAngles.z != InitialRotation)*
    
  •   			{*
    
  •   				transform.localRotation =*
    

_ Quaternion.Lerp (transform.localRotation, Quaternion.Euler (0, 0, InitialRotation), (Time.time - toggleFiredTime) * Speed);_

  •   				completedAction = false;*
    
  •   			}*
    
  •   			else if (isOpen && InitialState == InitialStateEnum.Open && transform.eulerAngles.z != InitialRotation)*
    
  •   			{*
    
  •   				transform.localRotation =*
    

_ Quaternion.Lerp (transform.localRotation, Quaternion.Euler (0, 0, InitialRotation), (Time.time - toggleFiredTime) * Speed);_

  •   				completedAction = false;*
    
  •   			}*
    
  •   		}*
    
  •   	}*
    
  •   }*
    
  •   else if(DoorType == DoorTypeEnum.Slide)*
    
  •   {*
    
  •   	completedAction = true;*
    
  •   	if (!isOpen && InitialState == InitialStateEnum.Open &&  Vector3.Distance(transform.localPosition, targetPosition) > .001f)* 
    
  •   	{*
    

_ transform.localPosition = Vector3.Slerp(transform.localPosition, targetPosition, (Time.time - toggleFiredTime) * Speed);_

  •   		completedAction = false;*
    
  •   	}* 
    
  •   	else if (isOpen && InitialState == InitialStateEnum.Closed && Vector3.Distance(transform.localPosition, targetPosition) > .001f)* 
    
  •   	{*
    

_ transform.localPosition = Vector3.Slerp(transform.localPosition, targetPosition, (Time.time - toggleFiredTime) * Speed);_

  •   		completedAction = false;*
    
  •   	}*
    
  •   	else if (!isOpen && InitialState == InitialStateEnum.Closed && Vector3.Distance(transform.localPosition, initialPosition) > .001f)*
    
  •   	{*
    

_ transform.localPosition = Vector3.Slerp(transform.localPosition, initialPosition, (Time.time - toggleFiredTime) * Speed);_

  •   		completedAction = false;*
    
  •   	}*
    
  •   	else if (isOpen && InitialState == InitialStateEnum.Open && Vector3.Distance(transform.localPosition, initialPosition) > .001f)*
    
  •   	{*
    

_ transform.localPosition = Vector3.Slerp(transform.localPosition, initialPosition, (Time.time - toggleFiredTime) * Speed);_

  •   		completedAction = false;*
    
  •   	}*
    
  •   }*
    
  • }*
  • void ToggleDoor()*
  • {*
  •   if(Speed <= 0)*
    
  •   {*
    
  •   	Debug.LogWarning("SimpleDoor Script WARNING - The Speed of Action seems to be 0 or negative, be aware that the door won't work on these conditions.");*
    
  •   }*
    
  •   toggleFiredTime = Time.time;*
    
  •   isOpen = !isOpen;*
    
  • }*
  • void OnTriggerEnter(Collider col)*
  • {*
  •   if(ActivationType == ActivationTypeEnum.Proximity)*
    
  •   {*
    
  •   	if(PlayerRecognition == PlayerRecognitionEnum.Tag)*
    
  •   	{*
    
  •   		if(col.gameObject.tag == PlayerTag)*
    
  •   		{*
    
  •   			ToggleDoor();*
    
  •   		}*
    
  •   	}*
    
  •   	else if(PlayerRecognition == PlayerRecognitionEnum.GameObj)*
    
  •   	{*
    
  •   		if(PlayerObj != null)*
    
  •   		{*
    
  •   			if(col.gameObject == PlayerObj)*
    
  •   			{*
    
  •   				ToggleDoor();*
    
  •   			}*
    
  •   		}*
    
  •   	}*
    
  •   }*
    
  •   else if (ActivationType == ActivationTypeEnum.ProximityAndInput)*
    
  •   {*
    
  •   	if(PlayerRecognition == PlayerRecognitionEnum.Tag)*
    
  •   	{*
    
  •   		if(col.gameObject.tag == PlayerTag)*
    
  •   		{*
    
  •   			isOnTriggerArea = true;*
    
  •   		}*
    
  •   	}*
    
  •   	else if(PlayerRecognition == PlayerRecognitionEnum.GameObj)*
    
  •   	{*
    
  •   		if(PlayerObj != null)*
    
  •   		{*
    
  •   			if(col.gameObject == PlayerObj)*
    
  •   			{*
    
  •   				isOnTriggerArea = true;*
    
  •   			}*
    
  •   		}*
    
  •   	}*
    
  •   }*
    
  • }*
  • void OnTriggerExit(Collider col)*
  • {*
  •   if(ActivationType == ActivationTypeEnum.Proximity)*
    
  •   {*
    
  •   	if(PlayerRecognition == PlayerRecognitionEnum.Tag)*
    
  •   	{*
    
  •   		if(col.gameObject.tag == PlayerTag)*
    
  •   		{*
    
  •   			ToggleDoor();*
    
  •   		}*
    
  •   	}*
    
  •   	else if(PlayerRecognition == PlayerRecognitionEnum.GameObj)*
    
  •   	{*
    
  •   		if(PlayerObj != null)*
    
  •   		{*
    
  •   			if(col.gameObject == PlayerObj)*
    
  •   			{*
    
  •   				ToggleDoor();*
    
  •   			}*
    
  •   		}*
    
  •   	}*
    
  •   }*
    
  •   else if (ActivationType == ActivationTypeEnum.ProximityAndInput)*
    
  •   {*
    
  •   	if(PlayerRecognition == PlayerRecognitionEnum.Tag)*
    
  •   	{*
    
  •   		if(col.gameObject.tag == PlayerTag)*
    
  •   		{*
    
  •   			isOnTriggerArea = false;*
    
  •   		}*
    
  •   	}*
    
  •   	else if(PlayerRecognition == PlayerRecognitionEnum.GameObj)*
    
  •   	{*
    
  •   		if(PlayerObj != null)*
    
  •   		{*
    
  •   			if(col.gameObject == PlayerObj)*
    
  •   			{*
    
  •   				isOnTriggerArea = false;*
    
  •   			}*
    
  •   		}*
    
  •   	}*
    
  •   }*
    
  • }*
  • void OnDestroy()*
  • {*
  •   if (DoorType == DoorTypeEnum.Swing)*
    
  •   {*
    
  •   	var pos = new Vector3 ();*
    
  •   	if(FlatAxis == FlatAxisEnum.X)*
    
  •   	{*
    
  •   		if (ActionSide == ActionSideEnum.Left) {*
    
  •   			pos.x += (doorMesh.bounds.size.x) / 2;*
    
  •   		} else if (ActionSide == ActionSideEnum.Rigth) {*
    
  •   			pos.x -= (doorMesh.bounds.size.x) / 2;*
    
  •   		}*
    
  •   	}*
    
  •   	else*
    
  •   	{*
    
  •   		if (ActionSide == ActionSideEnum.Left) {*
    
  •   			pos.z += (doorMesh.bounds.size.x) / 2;*
    
  •   		} else if (ActionSide == ActionSideEnum.Rigth) {*
    
  •   			pos.z -= (doorMesh.bounds.size.x) / 2;*
    
  •   		}*
    
  •   	}*
    
  •   	if (ActionSide == ActionSideEnum.Up)*
    
  •   	{*
    
  •   		pos.y -= (doorMesh.bounds.size.y) / 2;*
    
  •   	}*
    
  •   	else if (ActionSide == ActionSideEnum.Down)*
    
  •   	{*
    
  •   		pos.y += (doorMesh.bounds.size.y) / 2;*
    
  •   	}*
    
  •   	Vector3 diff = Vector3.Scale (doorMesh.bounds.extents, pos);*
    
  •   	transform.position -= Vector3.Scale (diff, transform.localScale);*
    
  •   	Vector3[] verts = doorMesh.vertices;* 
    
  •   	for (int i=0; i<verts.Length; i++) {*
    

_ verts -= pos;_
* }*
* doorMesh.vertices = verts;*
* doorMesh.RecalculateBounds ();*
* Collider col = gameObject.GetComponent();*
* if (col) {*
* if (col is BoxCollider) {*
* ((BoxCollider)col).center += pos;*
* } else if (col is CapsuleCollider) {*
* ((CapsuleCollider)col).center += pos;*
* } else if (col is SphereCollider) {*
* ((SphereCollider)col).center += pos;*
* }*
* }*
* }*
* }*
* bool DoorIsOpen()*
* {*
* if(completedAction)*
* return isOpen;*
* else*
* return !isOpen;*
* }*
* bool DoorIsActing()*
* {*
* return !completedAction;*
* }*
}
[89514-screen-shot-2017-03-05-at-150918-edited-1.jpg|89514]_
_

Hello @hexagonius,

I am aware and I realise it’s alot and pretty excessive for a door opening script but when I buy an asset from the asset store and the creator hasn’t replied to solve the issues, I turned to the community. I know it’s a long shot because there is sooooo much script, but I don’t know where the problem lies.

Thanks,